Nadrieril / dhall-rust

Maintainable configuration files, for Rust users
Other
303 stars 27 forks source link

Panic on parse error #155

Closed TristanCacqueray closed 4 years ago

TristanCacqueray commented 4 years ago

When trying to parse this expression: List/length [True, 42], for example by updating the test like so:

diff --git serde_dhall/tests/de.rs serde_dhall/tests/de.rs
index 41a44bd..487e0d5 100644
--- serde_dhall/tests/de.rs
+++ serde_dhall/tests/de.rs
@@ -10 +10 @@ fn test_de_typed() {
-    assert_eq!(parse::<bool>("True"), true);
+    assert_eq!(parse::<bool>("List/length [True, 42]"), true);

Results in


---- test_de_typed stdout ----
thread 'test_de_typed' panicked at 'attempt to subtract with overflow', /home/fedora/.cargo/registry/src/github.com-1ecc6299db9ec823/annotate-snippets-0.6.1/src/formatter/mod.rs:214:60
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:77
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1052
   5: std::io::Write::write_fmt
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libstd/io/mod.rs:1426
   6: std::io::impls::<impl std::io::Write for alloc::boxed::Box<W>>::write_fmt
             at src/libstd/io/impls.rs:156
   7: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   8: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   9: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:204
  10: std::panicking::default_hook
             at src/libstd/panicking.rs:221
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:472
  12: rust_begin_unwind
             at src/libstd/panicking.rs:380
  13: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  14: core::panicking::panic
             at src/libcore/panicking.rs:52
  15: annotate_snippets::formatter::DisplayListFormatter::format_source_line
             at /home/fedora/.cargo/registry/src/github.com-1ecc6299db9ec823/annotate-snippets-0.6.1/src/formatter/mod.rs:214
  16: annotate_snippets::formatter::DisplayListFormatter::format_line
             at /home/fedora/.cargo/registry/src/github.com-1ecc6299db9ec823/annotate-snippets-0.6.1/src/formatter/mod.rs:312
  17: annotate_snippets::formatter::DisplayListFormatter::format::{{closure}}
             at /home/fedora/.cargo/registry/src/github.com-1ecc6299db9ec823/annotate-snippets-0.6.1/src/formatter/mod.rs:106
  18: core::iter::adapters::map_fold::{{closure}}
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libcore/iter/adapters/mod.rs:772
  19: core::iter::traits::iterator::Iterator::fold::ok::{{closure}}
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libcore/iter/traits/iterator.rs:1900
  20: core::iter::traits::iterator::Iterator::try_fold
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libcore/iter/traits/iterator.rs:1776
  21: core::iter::traits::iterator::Iterator::fold
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libcore/iter/traits/iterator.rs:1903
  22: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libcore/iter/adapters/mod.rs:812
  23: core::iter::traits::iterator::Iterator::for_each
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libcore/iter/traits/iterator.rs:655
  24: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::spec_extend
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/liballoc/vec.rs:2054
  25: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/liballoc/vec.rs:2034
  26: <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/liballoc/vec.rs:1919
  27: core::iter::traits::iterator::Iterator::collect
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libcore/iter/traits/iterator.rs:1558
  28: annotate_snippets::formatter::DisplayListFormatter::format
             at /home/fedora/.cargo/registry/src/github.com-1ecc6299db9ec823/annotate-snippets-0.6.1/src/formatter/mod.rs:104
  29: dhall::error::builder::ErrorBuilder::format
             at dhall/src/error/builder.rs:158
  30: dhall::semantics::tck::typecheck::mk_span_err
             at dhall/src/semantics/tck/typecheck.rs:65
  31: dhall::semantics::tck::typecheck::type_one_layer::{{closure}}
             at dhall/src/semantics/tck/typecheck.rs:78
  32: dhall::semantics::tck::typecheck::type_one_layer
             at dhall/src/semantics/tck/typecheck.rs:138
  33: dhall::semantics::tck::typecheck::type_with
             at dhall/src/semantics/tck/typecheck.rs:781
  34: dhall::semantics::tck::typecheck::type_with::{{closure}}
             at dhall/src/semantics/tck/typecheck.rs:780
  35: dhall::syntax::ast::expr::ExprKind<SE>::traverse_ref::{{closure}}
             at dhall/src/syntax/ast/expr.rs:212
  36: dhall::syntax::ast::visitor::visit_ref
             at dhall/src/syntax/ast/visitor.rs:90
  37: dhall::syntax::ast::expr::ExprKind<SE>::traverse_ref_maybe_binder
             at dhall/src/syntax/ast/expr.rs:194
  38: dhall::syntax::ast::expr::ExprKind<SE>::traverse_ref
             at dhall/src/syntax/ast/expr.rs:212
  39: dhall::semantics::tck::typecheck::type_with
             at dhall/src/semantics/tck/typecheck.rs:780
  40: dhall::semantics::tck::typecheck::typecheck_with
             at dhall/src/semantics/tck/typecheck.rs:814
  41: dhall::Resolved::typecheck_with
             at dhall/src/lib.rs:101
  42: serde_dhall::value::Value::from_str_using_dhall_error_type
             at serde_dhall/src/lib.rs:204
  43: serde_dhall::value::Value::from_str
             at serde_dhall/src/lib.rs:195
  44: serde_dhall::de::from_str_check_type
             at ./src/lib.rs:326
  45: serde_dhall::de::from_str_auto_type
             at ./src/lib.rs:339
  46: de::test_de_typed::parse
             at serde_dhall/tests/de.rs:7
  47: de::test_de_typed
             at serde_dhall/tests/de.rs:10
  48: de::test_de_typed::{{closure}}
             at serde_dhall/tests/de.rs:5
  49: core::ops::function::FnOnce::call_once
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libcore/ops/function.rs:232
  50: <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/liballoc/boxed.rs:1015
  51: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:86
  52: std::panicking::try
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libstd/panicking.rs:281
  53: std::panic::catch_unwind
             at /rustc/b8cedc00407a4c56a3bda1ed605c6fc166655447/src/libstd/panic.rs:394
  54: test::run_test_in_process
             at src/libtest/lib.rs:539
  55: test::run_test::run_test_inner::{{closure}}
             at src/libtest/lib.rs:452
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Interestingly, adding an extra space, e.g. using "List/length [True, 42] ", doesn't panic and returns the correct error message.

Nadrieril commented 4 years ago

Interestingly, adding an extra space, e.g. using "List/length [True, 42] ", doesn't panic and returns the correct error message.

Oh, thanks for that remark, it made me find the error ! I have a fix up: https://github.com/Nadrieril/dhall-rust/pull/156