yorukot/superfile · error

error generating ps thumbnail, outputPath: %s : %w

Error message

error generating ps thumbnail, outputPath: %s : %w

What it means

This error is returned when the Ghostscript (gs) child process exits non-zero while converting a PostScript file to a thumbnail image. It wraps gs's stderr output so the actual interpreter error is visible. It signals the PS/EPS rasterization step failed.

Source

Thrown at src/pkg/file_preview/thumbnail_generator.go:136

func (g *psGenerator) generateThumbnail(inputPath string, outputPathWithoutExt string) (string, error) {
	outputPath := outputPathWithoutExt + thumbOutputExt
	ctx, cancel := context.WithTimeout(context.Background(), thumbGenerationTimeout)
	defer cancel()

	// gs -dSAFER -dBATCH -dNOPAUSE -sPageList=1 -sDEVICE=jpeg -r150 -sOutputFile=output.jpg input.ps
	outputParam := "-sOutputFile=" + outputPath
	gs := exec.CommandContext(ctx, "gs",
		"-dSAFER", "-dBATCH", "-dNOPAUSE", // Standard GS operators
		"-sPageList=1",  // Output only the first page
		"-sDEVICE=jpeg", // Output format
		"-r150",         // Resolution (the same as for pdf)
		outputParam,     // Result (variable because of golangci-lint)
		inputPath,       // Input file
	)

	err := gs.Run()
	if err != nil {
		return "", fmt.Errorf("error generating ps thumbnail, outputPath: %s : %w",
			outputPath, err)
	}

	return outputPath, nil
}

type ThumbnailGenerator struct {
	// This is a cache. Key -> Video file path, Value -> Thumbnail file path
	// TODO: We can potentially make it persistent, preventing generation
	// of thumbnail on every launch or superfile
	tempFilesCache map[string]string
	tempDirectory  string
	mu             sync.Mutex
	generators     []thumbnailGeneratorInterface
}

func NewThumbnailGenerator() (*ThumbnailGenerator, error) {
	tmp, err := os.MkdirTemp("", "superfiles-*")

View on GitHub (pinned to b72f550bc6)

Solutions

  1. Check gs is installed: `which gs`; install ghostscript if absent.
  2. Reproduce with the same gs flags manually to read the raw interpreter error.
  3. Validate the file is actually PostScript (`file <input>`); skip thumbnailing if not.
  4. If newer Ghostscript's -dSAFER blocks input/output paths, adjust the gs flags in the generator.
  5. Fall back to a generic PS/EPS icon on failure.

Example fix

// before
thumb, err := gen.generateThumbnail(psPath)
// after
thumb, err := gen.generateThumbnail(psPath)
if err != nil {
    log.Warnf("ps thumbnail failed: %v", err)
    thumb = defaultPSIconPath
}
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := exec.LookPath("gs"); err != nil { return errors.New("ghostscript not installed") }
head := make([]byte, 4); f, _ := os.Open(psPath); n, _ := f.Read(head); f.Close()
if !strings.HasPrefix(string(head[:n]), "%!") { return errors.New("not a PostScript file") }

Try / catch

thumb, err := gen.generateThumbnail(psPath)
if err != nil {
    log.Warnf("ps thumbnail failed: %v", err)
    thumb = "" // fall back to PS icon
}

Prevention

When it happens

Trigger: generateThumbnail invoking gs with the computed output parameter and inputPath when ghostscript is not installed, the .ps/.eps file is malformed or uses unsupported PostScript Level constructs, or the output location is unwritable.

Common situations: ghostscript not installed on the host; corrupt or non-PostScript content saved with a .ps extension; EPS files with broken previews; license/security policy changes in newer Ghostscript versions blocking certain operators (e.g. -dSAFER restricting file access).

Related errors


AI-assisted analysis of yorukot/superfile@b72f550bc6 (2026-09-01). Data as JSON: /api/errors/04290204fdda6854. Report an issue: GitHub.