Skip to content

Instantly share code, notes, and snippets.

@def-
Created April 1, 2015 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save def-/52cacd2a6e527b93ff42 to your computer and use it in GitHub Desktop.
Save def-/52cacd2a6e527b93ff42 to your computer and use it in GitHub Desktop.
import unittest, nre, optional_t
type ErrorType* = enum stacktrace, phperror, other
type Error* = object
lines*: string
etype*: ErrorType
proc categorizeError*(e: Error): Error =
if e.lines.find(re"stack trace:").isSome:
Error(lines: e.lines, etype: ErrorType.stacktrace)
else:
Error(lines: e.lines, etype: ErrorType.phperror)
suite "categorizeError":
test "stacktrace":
var input = Error(lines: "lolol o lololo l stack trace: rcoeucr hoeruch")
var result = categorizeError(input)
check(result.etype == ErrorType.stacktrace)
test "php error":
var input = Error(lines: "5496 FastCGI sent in stderr: \"PHP message: PHP Warning: array_key_exists(")
var result = categorizeError(input)
check(result.etype == ErrorType.phperror)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment