{"record":{"id":"1436e322028bc2cb","repo":"withastro/astro","slug":"cannotextractfonttype","errorCode":"CannotExtractFontType","errorMessage":"An error occurred while trying to extract the font type from ${url}.","messagePattern":"An error occurred while trying to extract the font type from (.+?)\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/assets/fonts/infra/node-font-type-extractor.ts","lineNumber":11,"sourceCode":"import { extname } from 'node:path';\nimport { AstroError, AstroErrorData } from '../../../core/errors/index.js';\nimport type { FontTypeExtractor } from '../definitions.js';\nimport type { FontType } from '../types.js';\nimport { isFontType } from '../utils.js';\n\nexport class NodeFontTypeExtractor implements FontTypeExtractor {\n\textract(url: string): FontType {\n\t\tconst extension = extname(url).slice(1);\n\t\tif (!isFontType(extension)) {\n\t\t\tthrow new AstroError(\n\t\t\t\t{\n\t\t\t\t\t...AstroErrorData.CannotExtractFontType,\n\t\t\t\t\tmessage: AstroErrorData.CannotExtractFontType.message(url),\n\t\t\t\t},\n\t\t\t\t{ cause: `Unexpected extension, got \"${extension}\"` },\n\t\t\t);\n\t\t}\n\t\treturn extension;\n\t}\n}\n","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/assets/fonts/infra/node-font-type-extractor.ts#L1-L22","documentation":"Thrown by NodeFontTypeExtractor.extract when the file extension of a font URL is not a recognized font type. The extractor takes the extension via extname(url), strips the dot, and validates it with isFontType(); any unrecognized extension is reported as CannotExtractFontType with the full url, carrying a cause string naming the bad extension.","triggerScenarios":"Calling extract(url) where the URL's path extension is not in the set of valid font extensions (e.g. .woff2/.woff/.ttf/.otf). A URL with no extension, an extension like .txt, .xml, .css, or a query-string-suffixed path parsed by extname will all trigger it.","commonSituations":"A font provider URL that points at a CSS file or HTML page instead of the actual font binary, a typo'd file extension, a URL whose real extension is after a query/hash that extname mishandles, or an upstream font source that redirects to a non-font asset.","solutions":["Confirm the URL resolves to a real font binary (.woff2/.woff/.ttf/.otf), not a CSS or HTML wrapper.","Copy the full URL from the error and open it in a browser to inspect what is served.","If the URL has query parameters, ensure the path portion still ends in a recognized extension.","Switch the source to a provider/URL that serves the raw font file."],"exampleFix":"// before\nsrc: 'https://example.com/styles/fonts.css'\n\n// after\nsrc: 'https://example.com/files/MyFont.woff2'","handlingStrategy":"validation","validationCode":"import { extname } from 'node:path';\nconst FONT_EXT = new Set(['woff', 'woff2', 'ttf', 'otf', 'eot']);\nfunction hasFontExtension(url: string): boolean {\n  return FONT_EXT.has(extname(new URL(url, 'http://x').pathname).slice(1).toLowerCase());\n}","typeGuard":null,"tryCatchPattern":"try { extractor.extract(url); }\ncatch (e) {\n  if (e instanceof AstroError && e.code === 'CannotExtractFontType') {\n    // switch to a URL that serves a real font binary\n  }\n}","preventionTips":["Point font sources at raw font files, never at CSS/HTML wrappers.","When copying URLs, open them in a browser to confirm they serve a font.","Avoid URLs whose real extension sits behind a query string."],"tags":["fonts","validation","build"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}