Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Improve error handling for polymorphic field data with missing type value

Aberta
#297 4 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
25/100
Tipo de issue
Bug
Clareza
Precisa de esclarecimento
Status de atividade
Estagnada
Stack de tecnologia
typescript
Domínio
data

Direção de pesquisa

Comece em packages/@contentlayer/core/src/generation/generate-dotpkg.ts, especialmente em idToFileName e no fluxo ao redor de makeDataExportFile. Reproduza o exemplo TypeScript de lista aninhada polimórfica, rastreie como o valor de tipo ausente chega à geração e verifique se o caso produz um erro tratado útil em vez do TypeError undefined.replace relatado.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

good first issue help wanted meta: never-stale topic: error-handling

I encountered an error with following code trying to add polymorphic nested objects to a list.

export const Link = defineNestedType(() => ({
    name: "Link",
    description: "Link to an external resource",
    fields: {
        text: {
            type: "string",
            required: true,
        },
        url: {
            type: "string",
            required: true,
        },
    },
}));

export const LinkList = defineNestedType(() => ({
    name: "LinkList",
    description: "List of links to external resources",
    fields: {
        text: {
            type: "string",
            required: true,
        },
        links: {
            type: "list",
            required: true,
            of: Link,
        },
    },
}));

export const NavbarLinks = defineDocumentType(() => ({
    name: "NavbarLinks",
    filePathPattern: "core/navbarLinks.json",
    isSingleton: true,
    fields: {
        links: {
            type: "list",
            of: [Link, LinkList],
            required: true,
        },
    },
}));

This produces following stack trace

TypeError: Cannot read properties of undefined (reading 'replace')
    at idToFileName (file://.../node_modules/@contentlayer/core/src/generation/generate-dotpkg.ts:389:89)
    at makeDataExportFile (file://.../node_modules/@contentlayer/core/src/generation/generate-dotpkg.ts:291:53)
    at file://.../node_modules/@contentlayer/core/src/generation/generate-dotpkg.ts:153:18
    at Array.map (<anonymous>)
    at next (file://.../node_modules/@contentlayer/core/src/generation/generate-dotpkg.ts:152:44)
    at Generator.next (<anonymous>)
    at ApplyFrame.apply (file://.../node_modules/@effect-ts/system/_src/Effect/gen.ts:148:36)
    at FiberContext.nextInstr (file://.../node_modules/@effect-ts/system/_src/Fiber/context.ts:357:28)
    at FiberContext.evaluateNow (file://.../node_modules/@effect-ts/system/_src/Fiber/context.ts:940:36)
    at file://.../node_modules/@effect-ts/system/_src/Fiber/context.ts:576:33

Fiber: #17 (started at: 2022-09-04T21:49:21.161Z) was supposed to continue to:

  a future continuation at packages/@contentlayer/core/src/generation/generate-dotpkg.ts:216:13

Fiber: #17 (started at: 2022-09-04T21:49:21.161Z) Execution trace:

  packages/@contentlayer/core/src/generation/generate-dotpkg.ts:144:22
  packages/@contentlayer/core/src/generation/generate-dotpkg.ts:143:60
  packages/@contentlayer/core/src/generation/generate-dotpkg.ts:125:10
  packages/@contentlayer/core/src/generation/generate-dotpkg.ts:82:13
  packages/@contentlayer/core/src/generation/generate-dotpkg.ts:78:16
Linguagem predominante
TypeScript
Estrelas
3.5k
Forks
192
Métricas de merge de PRs
Nenhum PR com merge em 30d

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de contentlayerdev/contentlayer

Todas as issues de contentlayerdev/contentlayer

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.