{"record":{"id":"ab721c3ca398f523","repo":"Billionmail/BillionMail","slug":"error-marshalling-company-profile-v","errorCode":null,"errorMessage":"error marshalling company profile: %v","messagePattern":"error marshalling company profile: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/internal/service/askai/project.go","lineNumber":438,"sourceCode":"\tfilename := fmt.Sprintf(PRODUCT_CONFIG_PATH+\"/%s/company_profile.json\", Domain)\n\tif !public.FileExists(filename) {\n\t\tcompanyProfileDefault := CompanyProfile{\n\t\t\tLegalCompanyName: \"\",\n\t\t\tWebSite:          \"\",\n\t\t\tCompanyProfile:   \"\",\n\t\t\tEmail:            \"\",\n\t\t\tPhone:            \"\",\n\t\t\tSupportUrl:       \"\",\n\t\t}\n\t\t// If the company profile file does not exist, return a default profile\n\t\t// This allows the system to handle cases where the profile has not been set up yet\n\t\t// and avoids errors when trying to read a non-existent file.\n\t\t// It also allows the user to create a new profile without needing to handle file not\n\t\t// found errors.\n\t\tcompanyProfileDefault.UpdateTime = public.GetNowTime()\n\t\tcompanyProfileJson, err := json.MarshalIndent(companyProfileDefault, \"\", \"  \")\n\t\tif err != nil {\n\t\t\treturn CompanyProfile{}, fmt.Errorf(\"error marshalling company profile: %v\", err)\n\t\t}\n\t\terr = os.WriteFile(filename, companyProfileJson, 0644)\n\t\tif err != nil {\n\t\t\treturn CompanyProfile{}, fmt.Errorf(\"error creating company profile file: %v\", err)\n\t\t}\n\t\treturn companyProfileDefault, nil\n\t}\n\tdata, err := os.ReadFile(filename)\n\tif err != nil {\n\t\treturn CompanyProfile{}, fmt.Errorf(\"error reading company profile file: %v\", err)\n\t}\n\tvar profile CompanyProfile\n\terr = json.Unmarshal(data, &profile)\n\tif err != nil {\n\t\treturn CompanyProfile{}, fmt.Errorf(\"error unmarshalling company profile: %v\", err)\n\t}\n\treturn profile, nil\n}","sourceCodeStart":420,"sourceCodeEnd":456,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/askai/project.go#L420-L456","documentation":"ReadCompanyProfile lazily creates a default company_profile.json when none exists for the domain. This error wraps json.MarshalIndent of the default CompanyProfile failing. With the all-string default struct this is essentially unreachable; it would require a struct field of unmarshalable type or a failing custom MarshalJSON introduced by future changes.","triggerScenarios":"json.MarshalIndent(companyProfileDefault, ...) errors — e.g. someone adds a non-JSON-serializable field (chan/func/cyclic) to CompanyProfile, or a custom MarshalJSON returns an error.","commonSituations":"Post-change regression: a developer adds a runtime-only field (mutex, connection handle) to CompanyProfile without a json:\"-\" tag or marshals an unsupported type.","solutions":["Check the wrapped %v error for json.UnsupportedTypeError and the offending field","Tag runtime-only fields with json:\"-\" or give them JSON-safe types","Fix any custom MarshalJSON on CompanyProfile or its fields"],"exampleFix":"// before\nConn net.Conn // unsupported type breaks MarshalIndent\n// after\nConn net.Conn `json:\"-\"` // excluded from serialization","handlingStrategy":"type-guard","validationCode":"if err := json.Marshal(CompanyProfile{}); err != nil {\n    // struct gained an unmarshalable field; fix before runtime\n}","typeGuard":"func profileIsSerializable(p CompanyProfile) bool {\n    _, err := json.Marshal(p)\n    return err == nil\n}","tryCatchPattern":"profile, err := ReadCompanyProfile(domain)\nif err != nil && strings.Contains(err.Error(), \"marshalling company profile\") {\n    log.Errorf(\"CompanyProfile struct not serializable: %v\", err)\n}","preventionTips":["Tag runtime-only fields on CompanyProfile with json:\"-\"","Add a regression test that marshals a fully populated CompanyProfile","Review new struct fields for JSON compatibility before merging"],"tags":["go","json","serialization"],"backgroundTag":"json-unsupported-type","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}