{"record":{"id":"cfbf053143ced1d0","repo":"withastro/astro","slug":"cannotdetermineweightandstylefromfontfile","errorCode":"CannotDetermineWeightAndStyleFromFontFile","errorMessage":"An error occurred while determining the `weight` and `style` from local family \"${family}\" font file: ${url}.","messagePattern":"An error occurred while determining the `weight` and `style` from local family \"(.+?)\" font file: (.+?)\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/assets/fonts/infra/fontace-font-file-reader.ts","lineNumber":16,"sourceCode":"import { readFileSync } from 'node:fs';\nimport { fontace } from 'fontace';\nimport { AstroError, AstroErrorData } from '../../../core/errors/index.js';\nimport type { FontFileReader } from '../definitions.js';\nimport type { Style } from '../types.js';\n\nexport class FontaceFontFileReader implements FontFileReader {\n\textract({ family, url }: { family: string; url: string }): { weight: string; style: Style } {\n\t\ttry {\n\t\t\tconst data = fontace(readFileSync(url));\n\t\t\treturn {\n\t\t\t\tweight: data.weight,\n\t\t\t\tstyle: data.style as Style,\n\t\t\t};\n\t\t} catch (cause) {\n\t\t\tthrow new AstroError(\n\t\t\t\t{\n\t\t\t\t\t...AstroErrorData.CannotDetermineWeightAndStyleFromFontFile,\n\t\t\t\t\tmessage: AstroErrorData.CannotDetermineWeightAndStyleFromFontFile.message(family, url),\n\t\t\t\t},\n\t\t\t\t{ cause },\n\t\t\t);\n\t\t}\n\t}\n}\n","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/assets/fonts/infra/fontace-font-file-reader.ts#L1-L26","documentation":"Thrown by FontaceFontFileReader.extract when the fontace library cannot parse a local font file to derive its weight and style. The reader does a synchronous readFileSync(url) and passes the buffer to fontace; if fontace throws (corrupt or unrecognized font), the error is wrapped as CannotDetermineWeightAndStyleFromFontFile with the family and url.","triggerScenarios":"Calling extract({ family, url }) on a local font file that is not a valid parseable font (e.g. a .txt renamed to .woff2), a truncated/corrupt binary, or an unsupported font container that fontace cannot introspect. Also thrown if readFileSync itself fails before fontace runs.","commonSituations":"User points a local() source at the wrong file, a font downloaded incompletely, a license/placeholder file, or a font format fontace does not yet support. Typically surfaces during astro build while resolving local families.","solutions":["Confirm the file at url is a valid, complete font (open it in a font tool or re-download).","Verify the path is correct and points to the intended .woff/.woff2/.ttf/.otf file.","Provide explicit weight and style in the font config so extraction is not required.","Re-download the font from the original source to rule out truncation.","Inspect the `cause` to see fontace's specific parse error."],"exampleFix":"// before\n{ family: 'MyFont', src: [local('MyFont')] }\n\n// after - specify weight/style explicitly to bypass extraction\n{ family: 'MyFont', weight: 700, style: 'normal', src: [local('MyFont-Bold')] }","handlingStrategy":"validation","validationCode":"import { existsSync, statSync } from 'node:fs';\nfunction isValidLocalFont(url: string): boolean {\n  return existsSync(url) && statSync(url).size > 0;\n}","typeGuard":null,"tryCatchPattern":"try { reader.extract({ family, url }); }\ncatch (e) {\n  if (e instanceof AstroError && e.code === 'CannotDetermineWeightAndStyleFromFontFile') {\n    // fall back to explicit weight/style from config\n  }\n}","preventionTips":["Always specify weight and style explicitly for local fonts to bypass extraction.","Validate local font files are non-empty and parseable before build.","Keep font sources under version control to detect corruption."],"tags":["fonts","filesystem","parsing","build"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}