Skip to content

Commit b930bc3

Browse files
committed
Remove yet more failure
1 parent 9ff7b3d commit b930bc3

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

src/error.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -481,21 +481,6 @@ impl PostgresDbError {
481481
routine: map.pop(&('R' as u8)).unwrap()
482482
}
483483
}
484-
485-
#[doc(hidden)]
486-
pub fn pretty_error(&self, query: &str) -> ~str {
487-
match self.position {
488-
Some(Position(pos)) =>
489-
format!("{}: {} at position {} in\n{}", self.severity,
490-
self.message, pos, query),
491-
Some(InternalPosition { position, query: ref inner_query }) =>
492-
format!("{}: {} at position {} in\n{} called from\n{}",
493-
self.severity, self.message, position, *inner_query,
494-
query),
495-
None => format!("{}: {} in\n{}", self.severity, self.message,
496-
query)
497-
}
498-
}
499484
}
500485

501486
/// An error encountered when communicating with the Postgres server
@@ -522,4 +507,6 @@ pub enum PostgresError {
522507
PgWrongType(PostgresType),
523508
/// An attempt was made to read from a column that does not exist
524509
PgInvalidColumn,
510+
/// A value was NULL but converted to a non-nullable Rust type
511+
PgWasNull,
525512
}

src/test.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use error::{PgConnectDbError,
2323
PgWrongParamCount,
2424
PgWrongType,
2525
PgInvalidColumn,
26+
PgWasNull,
2627
DnsError,
2728
MissingPassword,
2829
Position,
@@ -770,6 +771,18 @@ fn test_get_named_err() {
770771
};
771772
}
772773

774+
#[test]
775+
fn test_get_was_null() {
776+
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
777+
let stmt = or_fail!(conn.prepare("SELECT NULL::INT as id"));
778+
let mut result = or_fail!(stmt.query([]));
779+
780+
match result.next().unwrap().get::<uint, i32>(1) {
781+
Err(PgWasNull) => {}
782+
res => fail!("unexpected result {}", res),
783+
};
784+
}
785+
773786
#[test]
774787
fn test_custom_notice_handler() {
775788
static mut count: uint = 0;

src/types/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::io::util::LimitReader;
1010
use std::str;
1111
use time::Timespec;
1212

13-
use error::{PostgresError, PgWrongType, PgStreamError};
13+
use error::{PostgresError, PgWrongType, PgStreamError, PgWasNull};
1414
use types::array::{Array, ArrayBase, DimensionInfo};
1515
use types::range::{RangeBound, Inclusive, Exclusive, Range};
1616

@@ -378,7 +378,11 @@ macro_rules! from_map_impl(
378378
-> Result<$t, PostgresError> {
379379
// FIXME when you can specify Self types properly
380380
let ret: Result<Option<$t>, PostgresError> = FromSql::from_sql(ty, raw);
381-
ret.map(|ok| ok.unwrap())
381+
match ret {
382+
Ok(Some(val)) => Ok(val),
383+
Ok(None) => Err(PgWasNull),
384+
Err(err) => Err(err)
385+
}
382386
}
383387
}
384388
)
@@ -501,7 +505,11 @@ impl FromSql for HashMap<~str, Option<~str>> {
501505
-> Result<HashMap<~str, Option<~str>>, PostgresError> {
502506
// FIXME when you can specify Self types properly
503507
let ret: Result<Option<HashMap<~str, Option<~str>>>, PostgresError> = FromSql::from_sql(ty, raw);
504-
ret.map(|ok| ok.unwrap())
508+
match ret {
509+
Ok(Some(val)) => Ok(val),
510+
Ok(None) => Err(PgWasNull),
511+
Err(err) => Err(err)
512+
}
505513
}
506514
}
507515

0 commit comments

Comments
 (0)