{"record":{"id":"6ec4f3abd1daa458","repo":"shadow1ng/fscan","slug":"output-config-cannot-be-nil","errorCode":null,"errorMessage":"output config cannot be nil","messagePattern":"output config cannot be nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/output/manager.go","lineNumber":21,"sourceCode":"import (\n\t\"fmt\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"sync\"\n)\n\n// Manager 简化的输出管理器\ntype Manager struct {\n\tmu     sync.RWMutex\n\tconfig *ManagerConfig\n\twriter Writer\n\tclosed bool\n}\n\n// NewManager 创建新的输出管理器\nfunc NewManager(config *ManagerConfig) (*Manager, error) {\n\tif config == nil {\n\t\treturn nil, fmt.Errorf(\"output config cannot be nil\")\n\t}\n\n\t// 创建输出目录\n\tif err := createOutputDir(config.OutputPath); err != nil {\n\t\treturn nil, err\n\t}\n\n\tmanager := &Manager{\n\t\tconfig: config,\n\t}\n\n\t// 初始化写入器（内部会验证格式）\n\tif err := manager.initializeWriter(); err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn manager, nil\n}","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/common/output/manager.go#L3-L39","documentation":"NewManager validates that a ManagerConfig pointer is supplied before constructing the output Manager. A nil config cannot describe an output path or format, so construction fails fast with 'output config cannot be nil'.","triggerScenarios":"Calling NewManager(nil), or passing a *ManagerConfig variable that was never initialized (zero-value declared but not allocated).","commonSituations":"Refactoring that removed config construction, config-loading failure silently returning nil, or tests like TestNewManager_NilConfig exercising the guard.","solutions":["Allocate and populate a ManagerConfig before calling NewManager","Ensure your config loader returns a non-nil struct even on partial input","Add a nil check on the config source before constructing the manager"],"exampleFix":"// before\nmgr, err := NewManager(nil)\n// after\ncfg := &ManagerConfig{OutputPath: \"./out\", Format: FormatJSON}\nmgr, err := NewManager(cfg)","handlingStrategy":"validation","validationCode":"if cfg == nil {\n    cfg = &ManagerConfig{OutputPath: defaultPath, Format: FormatJSON}\n}\nmgr, err := NewManager(cfg)","typeGuard":null,"tryCatchPattern":"mgr, err := NewManager(cfg)\nif err != nil {\n    return fmt.Errorf(\"manager init: %w\", err)\n}","preventionTips":["Always allocate config structs with &ManagerConfig{...} or a loader that never returns nil","Assert config-loading success before constructing the manager","Add unit coverage for nil-config paths"],"tags":["output","nil-check","config"],"backgroundTag":"null-argument","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}