{"record":{"id":"807751ae5a4e3fe8","repo":"JanDeDobbeleer/oh-my-posh","slug":"unable-to-add-font-resource-using-addfontresourcew","errorCode":null,"errorMessage":"unable to add font resource using AddFontResourceW","messagePattern":"unable to add font resource using AddFontResourceW","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/font/install_windows.go","lineNumber":141,"sourceCode":"\n\tif err = k.SetStringValue(fontName, regValue); err != nil {\n\t\tlog.Error(err)\n\t\t// If this fails, remove the font file as well.\n\t\tif nexterr := os.Remove(fullPath); nexterr != nil {\n\t\t\treturn errors.New(\"unable to delete font file after registry key set error\")\n\t\t}\n\n\t\treturn fmt.Errorf(\"unable to set registry value: %s\", err.Error())\n\t}\n\n\tfontPtr, err := syscall.UTF16PtrFromString(fullPath)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tret, _, _ := addFontResourceW.Call(uintptr(unsafe.Pointer(fontPtr)))\n\tif ret == 0 {\n\t\treturn errors.New(\"unable to add font resource using AddFontResourceW\")\n\t}\n\n\tlog.Debug(\"font resource added successfully\")\n\n\treturn nil\n}\n","sourceCodeStart":123,"sourceCodeEnd":148,"githubUrl":"https://github.com/JanDeDobbeleer/oh-my-posh/blob/0976794618c5ed95de0985dded50de1b4dc914cb/src/cli/font/install_windows.go#L123-L148","documentation":"The final step of the Windows font install calls the Win32 AddFontResourceW API via syscall to make the font available in the current session. If the call returns 0, the font resource was not added, and install returns this error. At this point the registry entry was already written, so the font is registered but not loaded until reboot/logoff.","triggerScenarios":"addFontResourceW.Call with the UTF-16 pointer to the font file path returns 0 — invalid or non-font file content, path issues, or GDI failing to load the font file in the current session.","commonSituations":"Downloaded/extracted archive contained a corrupt or unsupported font file; file path with unexpected characters; GDI resource exhaustion; the file was modified or truncated after registration.","solutions":["Verify the extracted file is a valid .ttf/.otf (try opening it in the Windows font viewer).","Re-download/reinstall the font to rule out a corrupt archive.","Reboot or sign out/in — the registry entry exists, so the font may load in a new session even if AddFontResourceW failed.","Retry the install after confirming the font path contains no unusual characters."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// verify the file is a parseable font before installing\ndata, err := os.ReadFile(fullPath)\nif err != nil || len(data) < 4 {\n    return errors.New(\"font file missing or truncated\")\n}\n// ttf: \\x00\\x01\\x00\\x00 ; otf: 'OTTO'\nif !bytes.HasPrefix(data, []byte{0, 1, 0, 0}) && !bytes.HasPrefix(data, []byte(\"OTTO\")) {\n    return errors.New(\"not a valid ttf/otf file\")\n}","typeGuard":null,"tryCatchPattern":"if err := font.Install(env, name, report); err != nil {\n    if strings.Contains(err.Error(), \"AddFontResourceW\") {\n        log.Printf(\"font registered in registry but not loaded this session; a reboot/logoff will activate it\")\n        return nil // registry entry exists; treat as soft success\n    }\n    return err\n}","preventionTips":["Validate downloaded archives produce real .ttf/.otf files (magic bytes) before installing","Remember AddFontResourceW only affects the current session — a reboot also loads registered fonts","Reinstall the font if a previous partial install left a corrupt file"],"tags":["windows","win32","font","syscall","gdi"],"backgroundTag":"win32-api-call-failed","analyzedSha":"0976794618c5ed95de0985dded50de1b4dc914cb","analyzedAt":"2026-08-31T23:41:19.708Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}