Convert a batch of error exits to well-known numbers

This commit is contained in:
Erica Fischer 2022-09-13 16:33:39 -07:00
parent 8e46650da7
commit 02617c89fe
5 changed files with 80 additions and 38 deletions

View File

@ -943,3 +943,45 @@ Join block geometries to employment attributes:
```
$ tippecanoe-json-tool -c in_wac_S000_JT00_2015.csv tl_2010_18157_tabblock10.sort.json > blocks-wac.json
```
Error returns
=============
* 101: CSV file not found
* 102: UTF-8 decoding error in CSV file header
* 103: UTF-8 decoding error in CSV file body
* 104: Error closing CSV file
* 105: Error decoding vector tile
* 106: Error decoding protocol buffer while decoding vector tile
* 107: Impossible (<= 0) extent in vector tile
* 108: Impossible tile number for zoom level in vector tile
* 109: Non-archive file specified for decode without z/x/y
* 110: Error closing tile after decoding
* 111: Error opening mbtiles file with sqlite
* 112: Error performing sqlite integrity check on mbtiles file
* 113: Error selecting metadata from mbtiles file
* 114: Null key or value in mbtiles metadata table
* 115: Error opening file in directory of tiles
* 116: Error selecting tiles from mbtiles file
* 117: Impossible zoom level in mbtiles file
* 118: Null tile in mbtiles tiles table
* 119: Error selecting a single tile from the mbtiles tiles table
* 120: Null single tile in mbtiles tiles table
* 121: Error closing mbtiles file
* 122: Unrecognized command line option in tippecanoe-decode
* 123: Directory of tiles to be written already exists
* 124: metadata.json file already exists in directory of tiles
* 125: Tile can't be deleted from directory of tiles
* 126: Tile to be written already exists in directory of tiles
* 127: Zoom level directory can't be opened
* 128: X coordinate directory can't be opened
* 128: Can't create temporary sqlite database for metadata
* 129: Can't create metadata table in temporary sqlite database
* 130: JSON parsing error reading metadata.json
* 131: Top level of metadata.json is not a JSON object
* 132: Can't open mbtiles file for tippecanoe-enumerate
* 133: Error performing sqlite integrity check on mbtiles file
* 134: Error selecting from tiles table in mbtiles file
* 135: Impossible zoom level in mbtiles file
* 136: Can't close mbtiles file after enumerating
* 137: Unrecognized command line option for tippecanoe-enumerate

View File

@ -68,7 +68,7 @@ void readcsv(const char *fn, std::vector<std::string> &header, std::map<std::str
FILE *f = fopen(fn, "r");
if (f == NULL) {
perror(fn);
exit(EXIT_FAILURE);
exit(101);
}
std::string s;
@ -76,7 +76,7 @@ void readcsv(const char *fn, std::vector<std::string> &header, std::map<std::str
std::string err = check_utf8(s);
if (err != "") {
fprintf(stderr, "%s: %s\n", fn, err.c_str());
exit(EXIT_FAILURE);
exit(102);
}
header = csv_split(s.c_str());
@ -89,7 +89,7 @@ void readcsv(const char *fn, std::vector<std::string> &header, std::map<std::str
std::string err = check_utf8(s);
if (err != "") {
fprintf(stderr, "%s: %s\n", fn, err.c_str());
exit(EXIT_FAILURE);
exit(103);
}
std::vector<std::string> line = csv_split(s.c_str());
@ -105,7 +105,7 @@ void readcsv(const char *fn, std::vector<std::string> &header, std::map<std::str
if (fclose(f) != 0) {
perror("fclose");
exit(EXIT_FAILURE);
exit(104);
}
}

View File

@ -92,11 +92,11 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::set<std::st
try {
if (!tile.decode(message, was_compressed)) {
fprintf(stderr, "Couldn't parse tile %d/%u/%u\n", z, x, y);
exit(EXIT_FAILURE);
exit(105);
}
} catch (std::exception const &e) {
fprintf(stderr, "PBF decoding error in tile %d/%u/%u\n", z, x, y);
exit(EXIT_FAILURE);
exit(106);
}
if (stats) {
@ -159,7 +159,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::set<std::st
if (layer.extent <= 0) {
fprintf(stderr, "Impossible layer extent %lld in mbtiles\n", layer.extent);
exit(EXIT_FAILURE);
exit(107);
}
if (to_decode.size() != 0 && !to_decode.count(layer.name)) {
@ -202,7 +202,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::set<std::st
// X and Y are unsigned, so no need to check <0
if (x > (1ULL << z) || y > (1ULL << z)) {
fprintf(stderr, "Impossible tile %d/%u/%u\n", z, x, y);
exit(EXIT_FAILURE);
exit(108);
}
layer_to_geojson(layer, z, x, y, !pipeline, pipeline, pipeline, false, 0, 0, 0, !force, state);
@ -245,7 +245,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
return;
} else {
fprintf(stderr, "Must specify zoom/x/y to decode a single pbf file\n");
exit(EXIT_FAILURE);
exit(109);
}
}
}
@ -256,7 +256,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
}
if (close(fd) != 0) {
perror("close");
exit(EXIT_FAILURE);
exit(110);
}
} else {
perror(fname);
@ -272,13 +272,13 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
} else {
if (sqlite3_open(fname, &db) != SQLITE_OK) {
fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db));
exit(EXIT_FAILURE);
exit(111);
}
char *err = NULL;
if (sqlite3_exec(db, "PRAGMA integrity_check;", NULL, NULL, &err) != SQLITE_OK) {
fprintf(stderr, "%s: integrity_check: %s\n", fname, err);
exit(EXIT_FAILURE);
exit(112);
}
}
@ -299,7 +299,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
sqlite3_stmt *stmt2;
if (sqlite3_prepare_v2(db, sql2, -1, &stmt2, NULL) != SQLITE_OK) {
fprintf(stderr, "%s: select failed: %s\n", fname, sqlite3_errmsg(db));
exit(EXIT_FAILURE);
exit(113);
}
while (sqlite3_step(stmt2) == SQLITE_ROW) {
@ -308,7 +308,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
if (name == NULL || value == NULL) {
fprintf(stderr, "Corrupt mbtiles file: null metadata\n");
exit(EXIT_FAILURE);
exit(114);
}
if (exclude_meta.count((char *) name) == 0) {
@ -361,7 +361,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
FILE *f = fopen(fn.c_str(), "rb");
if (f == NULL) {
perror(fn.c_str());
exit(EXIT_FAILURE);
exit(115);
}
std::string s;
@ -379,7 +379,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
fprintf(stderr, "%s: select failed: %s\n", fname, sqlite3_errmsg(db));
exit(EXIT_FAILURE);
exit(116);
}
sqlite3_bind_int(stmt, 1, minzoom);
@ -407,7 +407,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
if (tz < 0 || tz >= 32) {
fprintf(stderr, "Impossible zoom level %d in mbtiles\n", tz);
exit(EXIT_FAILURE);
exit(117);
}
ty = (1LL << tz) - 1 - ty;
@ -415,7 +415,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
if (s == NULL) {
fprintf(stderr, "Corrupt mbtiles file: null entry in tiles table\n");
exit(EXIT_FAILURE);
exit(118);
}
handle(std::string(s, len), tz, tx, ty, to_decode, pipeline, stats, state);
@ -443,7 +443,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
fprintf(stderr, "%s: select failed: %s\n", fname, sqlite3_errmsg(db));
exit(EXIT_FAILURE);
exit(119);
}
sqlite3_bind_int(stmt, 1, z);
@ -456,7 +456,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
if (s == NULL) {
fprintf(stderr, "Corrupt mbtiles file: null entry in tiles table\n");
exit(EXIT_FAILURE);
exit(120);
}
if (z != oz) {
@ -477,13 +477,13 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
if (sqlite3_close(db) != SQLITE_OK) {
fprintf(stderr, "%s: could not close database: %s\n", fname, sqlite3_errmsg(db));
exit(EXIT_FAILURE);
exit(121);
}
}
void usage(char **argv) {
fprintf(stderr, "Usage: %s [-s projection] [-Z minzoom] [-z maxzoom] [-l layer ...] file.mbtiles [zoom x y]\n", argv[0]);
exit(EXIT_FAILURE);
exit(122);
}
int main(int argc, char **argv) {

View File

@ -35,7 +35,7 @@ void dir_write_tile(const char *outdir, int z, int tx, int ty, std::string const
struct stat st;
if (stat(newdir.c_str(), &st) == 0) {
fprintf(stderr, "Can't write tile to already existing %s\n", newdir.c_str());
exit(EXIT_FAILURE);
exit(123);
}
std::ofstream pbfFile(newdir, std::ios::out | std::ios::binary);
@ -75,7 +75,7 @@ void check_dir(const char *dir, char **argv, bool force, bool forcetable) {
fprintf(stderr, "%s: Tileset \"%s\" already exists. You can use --force if you want to delete the old tileset.\n", argv[0], dir);
fprintf(stderr, "%s: %s: file exists\n", argv[0], meta.c_str());
if (!forcetable) {
exit(EXIT_FAILURE);
exit(124);
}
}
}
@ -93,11 +93,11 @@ void check_dir(const char *dir, char **argv, bool force, bool forcetable) {
if (force) {
if (unlink(fn.c_str()) != 0) {
perror(fn.c_str());
exit(EXIT_FAILURE);
exit(125);
}
} else {
fprintf(stderr, "%s: file exists\n", fn.c_str());
exit(EXIT_FAILURE);
exit(126);
}
}
}
@ -116,7 +116,7 @@ std::vector<zxy> enumerate_dirtiles(const char *fname, int minzoom, int maxzoom)
DIR *d2 = opendir(z.c_str());
if (d2 == NULL) {
perror(z.c_str());
exit(EXIT_FAILURE);
exit(127);
}
struct dirent *dp2;
@ -128,7 +128,7 @@ std::vector<zxy> enumerate_dirtiles(const char *fname, int minzoom, int maxzoom)
DIR *d3 = opendir(x.c_str());
if (d3 == NULL) {
perror(x.c_str());
exit(EXIT_FAILURE);
exit(128);
}
struct dirent *dp3;
@ -165,11 +165,11 @@ sqlite3 *dirmeta2tmp(const char *fname) {
if (sqlite3_open("", &db) != SQLITE_OK) {
fprintf(stderr, "Temporary db: %s\n", sqlite3_errmsg(db));
exit(EXIT_FAILURE);
exit(129);
}
if (sqlite3_exec(db, "CREATE TABLE metadata (name text, value text);", NULL, NULL, &err) != SQLITE_OK) {
fprintf(stderr, "Create metadata table: %s\n", err);
exit(EXIT_FAILURE);
exit(129);
}
std::string name = fname;
@ -183,12 +183,12 @@ sqlite3 *dirmeta2tmp(const char *fname) {
json_object *o = json_read_tree(jp);
if (o == NULL) {
fprintf(stderr, "%s: metadata parsing error: %s\n", name.c_str(), jp->error);
exit(EXIT_FAILURE);
exit(130);
}
if (o->type != JSON_HASH) {
fprintf(stderr, "%s: bad metadata format\n", name.c_str());
exit(EXIT_FAILURE);
exit(131);
}
for (size_t i = 0; i < o->value.object.length; i++) {

View File

@ -8,13 +8,13 @@ void enumerate(char *fname) {
if (sqlite3_open(fname, &db) != SQLITE_OK) {
fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db));
exit(EXIT_FAILURE);
exit(132);
}
char *err = NULL;
if (sqlite3_exec(db, "PRAGMA integrity_check;", NULL, NULL, &err) != SQLITE_OK) {
fprintf(stderr, "%s: integrity_check: %s\n", fname, err);
exit(EXIT_FAILURE);
exit(133);
}
const char *sql = "SELECT zoom_level, tile_column, tile_row from tiles order by zoom_level, tile_column, tile_row;";
@ -22,7 +22,7 @@ void enumerate(char *fname) {
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
fprintf(stderr, "%s: select failed: %s\n", fname, sqlite3_errmsg(db));
exit(EXIT_FAILURE);
exit(134);
}
while (sqlite3_step(stmt) == SQLITE_ROW) {
@ -32,7 +32,7 @@ void enumerate(char *fname) {
if (zoom < 0 || zoom > 31) {
fprintf(stderr, "Corrupt mbtiles file: impossible zoom level %lld\n", zoom);
exit(EXIT_FAILURE);
exit(135);
}
y = (1LL << zoom) - 1 - y;
@ -43,13 +43,13 @@ void enumerate(char *fname) {
if (sqlite3_close(db) != SQLITE_OK) {
fprintf(stderr, "%s: could not close database: %s\n", fname, sqlite3_errmsg(db));
exit(EXIT_FAILURE);
exit(136);
}
}
void usage(char **argv) {
fprintf(stderr, "Usage: %s file.mbtiles ...\n", argv[0]);
exit(EXIT_FAILURE);
exit(137);
}
int main(int argc, char **argv) {