1package lib 2 3import ( 4 "fmt" 5 "os" 6 "runtime" 7) 8 9// Lookalike for C's __FILE__ and __LINE__ printing. 10 11func InternalCodingErrorIf(condition bool) { 12 if !condition { 13 return 14 } 15 _, fileName, fileLine, ok := runtime.Caller(1) 16 if ok { 17 fmt.Fprintf( 18 os.Stderr, 19 "Internal coding error detected at file %s line %d\n", 20 fileName, 21 fileLine, 22 ) 23 } else { 24 fmt.Fprintf( 25 os.Stderr, 26 "Internal coding error detected at file %s line %s\n", 27 "(unknown)", 28 "(unknown)", 29 ) 30 } 31 // Uncomment this and re-run if you want to get a stack trace to get the 32 // call-tree that led to the indicated file/line: 33 // panic("eek") 34 os.Exit(1) 35} 36 37func InternalCodingErrorPanic(message string) { 38 _, fileName, fileLine, ok := runtime.Caller(1) 39 if ok { 40 panic( 41 fmt.Sprintf( 42 "Internal coding error detected at file %s line %d: %s\n", 43 fileName, 44 fileLine, 45 message, 46 ), 47 ) 48 } else { 49 panic( 50 fmt.Sprintf( 51 "Internal coding error detected at file %s line %s: %s\n", 52 "(unknown)", 53 "(unknown)", 54 message, 55 ), 56 ) 57 } 58 os.Exit(1) 59} 60