File: error.bs

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,004 kB
  • sloc: ansic: 261,462; cpp: 140,405; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (61 lines) | stat: -rw-r--r-- 1,224 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use core:lang;

/**
 * Thrown when an invalid table name is encountered.
 */
class NoSuchTable extends SyntaxError {
	init(SrcPos pos, Str name) {
		init(pos, "No table named ${name} is known.") {}
	}
}

/**
 * Thrown when we don't find a column.
 */
class NoSuchColumn extends SyntaxError {
	init(SrcPos pos, Str col, Str table) {
		init(pos, "No column named ${col} in ${table}.") {}
	}
}

/**
 * Thrown on dupliate alias declaration.
 */
class DuplicateAlias extends SyntaxError {
	init(SrcPos pos, Str alias) {
		init(pos, "The alias ${alias} is already defined in this query.") {}
	}
}


/**
 * Error in the database schema.
 */
class SchemaError extends SQLError {
	init(Str message, Table expected, Schema actual) {
		init(message) {
			expected = expected;
			actual = actual;
		}
	}

	private Table expected;
	private Schema actual;

	void message(StrBuf out) : override {
		super:message(out);

		out << "\nExpected these columns in table " << actual.name << "\n";
		out.indent();
		for (c in expected.columns)
			out << c << "\n";
		out.dedent();
		out << "But got the following columns:\n";
		out.indent();
		for (Nat i = 0; i < actual.count; i++) {
			out << actual[i];
			out << "\n";
		}
		out.dedent();
	}
}