1
Fork 0

std: Add a to_str impl for json::error.

This commit is contained in:
Erick Tryzelaar 2012-06-11 08:32:38 -07:00 committed by Graydon Hoare
parent ac4ac328ee
commit a816176eb5
2 changed files with 10 additions and 3 deletions

View file

@ -12,6 +12,7 @@ import io::writer_util;
import result; import result;
import std::{map, json, tempfile, term, sort, getopts}; import std::{map, json, tempfile, term, sort, getopts};
import map::hashmap; import map::hashmap;
import json::to_str;
import str; import str;
import vec; import vec;
import getopts::{optflag, optopt, opt_present}; import getopts::{optflag, optopt, opt_present};
@ -450,7 +451,7 @@ fn try_parse_sources(filename: str, sources: map::hashmap<str, source>) {
} }
} }
ok(_) { fail "malformed sources.json"; } ok(_) { fail "malformed sources.json"; }
err(e) { fail #fmt("%s:%u:%u: %s", filename, e.line, e.col, e.msg); } err(e) { fail #fmt("%s:%s", filename, e.to_str()); }
} }
} }
@ -570,7 +571,7 @@ fn load_source_info(c: cargo, src: source) {
"(source info is not a dict)"); "(source info is not a dict)");
} }
err(e) { err(e) {
warn(#fmt("%s:%u:%u: %s", src.name, e.line, e.col, e.msg)); warn(#fmt("%s:%s", src.name, e.to_str()));
} }
}; };
} }
@ -599,7 +600,7 @@ fn load_source_packages(c: cargo, src: source) {
"(packages is not a list)"); "(packages is not a list)");
} }
err(e) { err(e) {
warn(#fmt("%s:%u:%u: %s", src.name, e.line, e.col, e.msg)); warn(#fmt("%s:%s", src.name, e.to_str()));
} }
}; };
} }

View file

@ -603,6 +603,12 @@ impl of to_str::to_str for json {
fn to_str() -> str { to_str(self) } fn to_str() -> str { to_str(self) }
} }
impl of to_str::to_str for error {
fn to_str() -> str {
#fmt("%u:%u: %s", self.line, self.col, self.msg)
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
fn mk_dict(items: [(str, json)]) -> json { fn mk_dict(items: [(str, json)]) -> json {