shadow1ng/fscan · error
output config cannot be nil
Error message
output config cannot be nil
What it means
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'.
Source
Thrown at common/output/manager.go:21
import (
"fmt"
"os"
"path/filepath"
"sync"
)
// Manager 简化的输出管理器
type Manager struct {
mu sync.RWMutex
config *ManagerConfig
writer Writer
closed bool
}
// NewManager 创建新的输出管理器
func NewManager(config *ManagerConfig) (*Manager, error) {
if config == nil {
return nil, fmt.Errorf("output config cannot be nil")
}
// 创建输出目录
if err := createOutputDir(config.OutputPath); err != nil {
return nil, err
}
manager := &Manager{
config: config,
}
// 初始化写入器(内部会验证格式)
if err := manager.initializeWriter(); err != nil {
return nil, err
}
return manager, nil
}View on GitHub (pinned to 95cc12e753)
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
Example fix
// before
mgr, err := NewManager(nil)
// after
cfg := &ManagerConfig{OutputPath: "./out", Format: FormatJSON}
mgr, err := NewManager(cfg) Defensive patterns
Strategy: validation
Validate before calling
if cfg == nil {
cfg = &ManagerConfig{OutputPath: defaultPath, Format: FormatJSON}
}
mgr, err := NewManager(cfg) Try / catch
mgr, err := NewManager(cfg)
if err != nil {
return fmt.Errorf("manager init: %w", err)
} Prevention
- 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
When it happens
Trigger: Calling NewManager(nil), or passing a *ManagerConfig variable that was never initialized (zero-value declared but not allocated).
Common situations: Refactoring that removed config construction, config-loading failure silently returning nil, or tests like TestNewManager_NilConfig exercising the guard.
Related errors
- unsupported format: %s
- result cannot be nil
- result cannot be nil
- output manager is closed
- failed to create TXT file: %w
AI-assisted analysis of shadow1ng/fscan@95cc12e753 (2026-09-06).
Data as JSON: /api/errors/6ec4f3abd1daa458.
Report an issue: GitHub.