{"record":{"id":"e5e37715fd753a68","repo":"wailsapp/wails","slug":"invalid-font-style","errorCode":null,"errorMessage":"Invalid font style","messagePattern":"Invalid font style","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v2/internal/frontend/desktop/windows/winc/font.go","lineNumber":36,"sourceCode":"\tFontItalic    byte = 0x02\n\tFontUnderline byte = 0x04\n\tFontStrikeOut byte = 0x08\n)\n\nfunc init() {\n\tDefaultFont = NewFont(\"MS Shell Dlg 2\", 8, 0)\n}\n\ntype Font struct {\n\thfont     w32.HFONT\n\tfamily    string\n\tpointSize int\n\tstyle     byte\n}\n\nfunc NewFont(family string, pointSize int, style byte) *Font {\n\tif style > FontBold|FontItalic|FontUnderline|FontStrikeOut {\n\t\tpanic(\"Invalid font style\")\n\t}\n\n\t//Retrive screen DPI\n\thDC := w32.GetDC(0)\n\tdefer w32.ReleaseDC(0, hDC)\n\tscreenDPIY := w32.GetDeviceCaps(hDC, w32.LOGPIXELSY)\n\n\tfont := Font{\n\t\tfamily:    family,\n\t\tpointSize: pointSize,\n\t\tstyle:     style,\n\t}\n\n\tfont.hfont = font.createForDPI(screenDPIY)\n\tif font.hfont == 0 {\n\t\tpanic(\"CreateFontIndirect failed\")\n\t}\n","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/wailsapp/wails/blob/0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3/v2/internal/frontend/desktop/windows/winc/font.go#L18-L54","documentation":"NewFont validates the style bitmask before creating the font: style must be a subset of FontBold|FontItalic|FontUnderline|FontStrikeOut (values 1|2|4|8 = 0x0F). Any style byte with bits above 0x0F — including accidentally passing a point size, a color, or a style enum from a different API — panics with 'Invalid font style'. This is a pure argument-validation panic, not a Win32 failure.","triggerScenarios":"Calling winc.NewFont(family, size, style) with style > 0x0F, e.g. NewFont(\"Segoe UI\", 9, 16); mixing up parameter order so a size lands in the style slot; OR-ing in a custom flag not defined by winc.","commonSituations":"Porting font code from other toolkits whose style enums use different bit values; copy-paste parameter-order mistakes (family/pointSize/style swapped).","solutions":["Build the style only from winc constants: winc.FontBold, winc.FontItalic, winc.FontUnderline, winc.FontStrikeOut (OR them together)","Mask the style defensively before the call: style & (FontBold|FontItalic|FontUnderline|FontStrikeOut)","Double-check the NewFont signature (family string, pointSize int, style byte) when porting code"],"exampleFix":"// before\nfnt := winc.NewFont(\"Segoe UI\", 9, 12) // 12 = 0b1100 -> only underline(4)+strikeout(8) bits, ok; but 16+ panics\nfnt := winc.NewFont(\"Segoe UI\", 9, winc.FontBold|16) // invalid bit -> panic\n\n// after\nfnt := winc.NewFont(\"Segoe UI\", 9, winc.FontBold|winc.FontItalic) // subset of 0x0F","handlingStrategy":"validation","validationCode":"const fontStyleMask = winc.FontBold | winc.FontItalic | winc.FontUnderline | winc.FontStrikeOut // 0x0F\n\nfunc safeStyle(s byte) byte { return s & fontStyleMask }\n\nfnt := winc.NewFont(\"Segoe UI\", 9, safeStyle(incomingStyle))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compose styles only from the four winc constants","When porting font code, re-check the (family, pointSize, style byte) signature"],"tags":["windows","gdi","font","winc","panic","invalid-argument"],"backgroundTag":null,"analyzedSha":"0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3","analyzedAt":"2026-08-15T14:17:36.034Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}