Skip to content

debug-fail-message

C#styleno fixdefault: offcsharp/stylecop

Reports a Debug.Fail call with a constant blank message. With the type layer the call is checked against System.Diagnostics.Debug; without it any call written Debug.Fail is. No fix.

Debug.Fail is reached only when something is wrong, and the message is the only information about what. An empty message leaves the reader of the failure with a stack trace and no idea of the cause.

To fix, say what went wrong.

Reported
...
Debug.Assert(true, "why");
Debug.Fail("");
}
...
public void Own() { }
...
After the fix
...
Debug.Assert(true, "why");
Debug.Fail("");
}
...
public void Own() { }
...
csharp:
lint:
rules:
debug-fail-message: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line debug-fail-message in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
StyleCop SA1406 full