shadow1ng/fscan · error

unsupported format: %s

Error message

unsupported format: %s

What it means

Default-branch guard in Manager.initializeWriter: m.config.Format does not match any known output format constant (FormatTXT, FormatJSON, FormatCSV), so no Writer can be constructed for the requested output format string. It indicates a misconfigured/unknown format value passed into the output manager config.

Source

Thrown at common/output/manager.go:60

func createOutputDir(outputPath string) error {
	dir := filepath.Dir(outputPath)
	return os.MkdirAll(dir, DefaultDirPermissions)
}

// initializeWriter 初始化写入器
func (m *Manager) initializeWriter() error {
	var writer Writer
	var err error

	switch m.config.Format {
	case FormatTXT:
		writer, err = NewTXTWriter(m.config.OutputPath)
	case FormatJSON:
		writer, err = NewJSONWriter(m.config.OutputPath)
	case FormatCSV:
		writer, err = NewCSVWriter(m.config.OutputPath)
	default:
		return fmt.Errorf("unsupported format: %s", m.config.Format)
	}

	if err != nil {
		return err
	}

	m.writer = writer
	return m.writer.WriteHeader()
}

// SaveResult 保存扫描结果
func (m *Manager) SaveResult(result *ScanResult) error {
	m.mu.RLock()
	defer m.mu.RUnlock()

	if m.closed {
		return fmt.Errorf("output manager is closed")
	}

View on GitHub (pinned to 95cc12e753)

Solutions

  1. Use the exported Format constants (FormatTXT/FormatJSON/FormatCSV) instead of raw strings
  2. Check the exact constant spelling/case and correct the config value
  3. Validate/normalize the format string before building ManagerConfig

Example fix

// before
cfg.Format = "json" // if constant differs
// after
cfg.Format = FormatJSON
Defensive patterns

Strategy: validation

Validate before calling

switch cfg.Format {
case FormatTXT, FormatJSON, FormatCSV:
    // ok
default:
    return fmt.Errorf("format must be one of txt/json/csv, got %q", cfg.Format)
}

Try / catch

mgr, err := NewManager(cfg)
if err != nil && strings.Contains(err.Error(), "unsupported format") {
    cfg.Format = FormatTXT // safe fallback
    mgr, err = NewManager(cfg)
}

Prevention

When it happens

Trigger: Passing ManagerConfig.Format set to an unknown value (typo like 'jsn', wrong case like 'json' if constants differ, or empty string not handled).

Common situations: Hand-written config files or CLI flags feeding a free-form format string, YAML/JSON config with a misspelled format, version change where a format was removed.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of shadow1ng/fscan@95cc12e753 (2026-09-06). Data as JSON: /api/errors/5c573ac8707a4ae4. Report an issue: GitHub.