{"record":{"id":"8bb2cfb92d7c0527","repo":"Billionmail/BillionMail","slug":"error-creating-company-profile-file-v","errorCode":null,"errorMessage":"error creating company profile file: %v","messagePattern":"error creating company profile file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/askai/project.go","lineNumber":442,"sourceCode":"\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}\n\n// SaveCompanyProfile saves the provided CompanyProfile to a JSON file based on the domain.\n// It creates the directory if it does not exist and writes the profile information to company_profile.json\nfunc SaveCompanyProfile(Domain string, profile CompanyProfile) error {","sourceCodeStart":424,"sourceCodeEnd":460,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/askai/project.go#L424-L460","documentation":"When company_profile.json is missing, ReadCompanyProfile writes a serialized default profile with os.WriteFile (mode 0644). This error wraps that write failing. Note the parent directory PRODUCT_CONFIG_PATH/<domain> is never created here, so a missing domain directory (ENOENT) is the most common cause.","triggerScenarios":"os.WriteFile fails while creating the default profile: parent directory PRODUCT_CONFIG_PATH/<domain> does not exist and is not auto-created (ENOENT); permission denied; read-only filesystem; disk full; company_profile.json path is a directory.","commonSituations":"First access for a brand-new domain whose config directory was never created; read-only container volume; service user lacking write access to PRODUCT_CONFIG_PATH; PRODUCT_CONFIG_PATH misconfigured.","solutions":["Read the wrapped %v error for the OS cause (ENOENT, EACCES, ENOSPC)","Pre-create the domain directory: os.MkdirAll(fmt.Sprintf(PRODUCT_CONFIG_PATH+\"/%s\", Domain), 0o755) before WriteFile","Ensure the process user has write permission on PRODUCT_CONFIG_PATH (chown/chmod, fix volume mount)","Check disk space/quotas"],"exampleFix":"// before\nerr = os.WriteFile(filename, companyProfileJson, 0644)\n// after\nos.MkdirAll(filepath.Dir(filename), 0o755)\nif err := os.WriteFile(filename, companyProfileJson, 0o644); err != nil {\n    return CompanyProfile{}, fmt.Errorf(\"error creating company profile file: %w\", err)\n}","handlingStrategy":"validation","validationCode":"func ensureDomainConfigDir(domain string) error {\n    return os.MkdirAll(fmt.Sprintf(\"%s/%s\", PRODUCT_CONFIG_PATH, domain), 0o755)\n}\n// before first ReadCompanyProfile for a domain:\nif err := ensureDomainConfigDir(domain); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":"profile, err := ReadCompanyProfile(domain)\nif err != nil && strings.Contains(err.Error(), \"creating company profile file\") {\n    log.Errorf(\"Cannot initialize company profile for %s: %v — check dir/permissions\", domain, err)\n    // return empty default profile to degrade gracefully\n}","preventionTips":["Create the domain config directory at domain provisioning time","Ensure PRODUCT_CONFIG_PATH is on a writable volume for the service user","Watch for ENOSPC via disk monitoring","Validate PRODUCT_CONFIG_PATH configuration at startup"],"tags":["go","filesystem","io","permissions"],"backgroundTag":"file-write-failed","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"}