NickeManarin/ScreenToGif · warning · Exception

output

Error message

output

What it means

EncodingManager runs the user's preset.CustomCommands via cmd /c, captures stdout and stderr asynchronously, and if StandardError is non-whitespace, throws new Exception(output) where output is the accumulated stdout+stderr text. The exception message is therefore the raw command output, not a fixed label.

Source

Thrown at ScreenToGif/Util/EncodingManager.cs:1289

                            UseShellExecute = false,
                            CreateNoWindow = true
                        };

                        using (var process = new Process())
                        {
                            process.StartInfo = procStartInfo;
                            process.Start();

                            var message = await process.StandardOutput.ReadToEndAsync();
                            var error = await process.StandardError.ReadToEndAsync();

                            if (!string.IsNullOrWhiteSpace(message))
                                output += message + Environment.NewLine;

                            if (!string.IsNullOrWhiteSpace(error))
                            {
                                output += error + Environment.NewLine;
                                throw new Exception(output);
                            }

                            process.WaitForExit(1000);
                        }
                    }

                    SetCommand(id, true, command, output);
                }
                catch (Exception e)
                {
                    LogWriter.Log(e, "It was not possible to run the post encoding command.");
                    SetCommand(id, false, command, output, e);
                }
                finally
                {
                    Update(id, 4, watch.Elapsed);
                    watch.Restart();
                }

View on GitHub (pinned to a4d0a67c21)

Solutions

  1. Test the custom command directly in a cmd shell with the substituted {p}/{f}/{u} values.
  2. If the command intentionally writes to stderr, redirect stderr to nul or capture only the exit code.
  3. Fix placeholder quoting — paths with spaces must be double-quoted in the user command.
  4. Run the command with absolute paths rather than relying on PATH.

Example fix

// before
if (!string.IsNullOrWhiteSpace(error))
{
    output += error + Environment.NewLine;
    throw new Exception(output);
}

// after
if (!string.IsNullOrWhiteSpace(error))
{
    output += error + Environment.NewLine;
    throw new Exception($"Post-encoding command failed. Output:\n{output}");
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate the user command parses and the executable exists before running
foreach (var line in preset.CustomCommands.Split('\n', StringSplitOptions.RemoveEmptyEntries))
{
    if (string.IsNullOrWhiteSpace(line)) continue;
    // optionally resolve the executable on PATH and warn if missing
}

Type guard

// n/a

Try / catch

try { /* run cmd /c */ }
catch (Exception e) when (e.Message.Contains(output))
{ LogWriter.Log(e, "post-encode command"); SetCommand(id, false, command, output, e); }

Prevention

When it happens

Trigger: preset.ExecuteCustomCommands && preset.CustomCommands is set, and at least one line writes to stderr. Lines are split on '\n' and each is run as `cmd /c <line>`.

Common situations: User's post-encode hook script has a typo, wrong path, or missing dependency; the tool legitimately writes to stderr even on success (e.g. ffmpeg-style progress on stderr); placeholder substitution produced an invalid command; quoted path issue with {p}/{f}/{u} replacement.

Related errors


AI-assisted analysis of NickeManarin/ScreenToGif@a4d0a67c21 (2026-08-13). Data as JSON: /api/errors/c3a018c4eeb52ef5. Report an issue: GitHub.