Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NumError(ParseIntError { kind: InvalidDigit }) #662

Closed
TonyMistark opened this issue Nov 1, 2023 · 1 comment
Closed

NumError(ParseIntError { kind: InvalidDigit }) #662

TonyMistark opened this issue Nov 1, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@TonyMistark
Copy link

Describe the bug

use std::fs::File;
use std::io::prelude::*;
use docx_rs::*;

fn main() {
    let docx = hello_docx().unwrap();
    println!("{:?}", docx);
    
}

pub fn hello_docx() -> Result<Docx, ReaderError> {
    // My original docx file generates an error when using read_docx to read it.
    let filename = String::from("docx-rs.docx");
    // The file is named docx-rs.docx, 
    // which was opened with LibreOffice and saved as docx-rs01.docx. 
    // When using read_docx on this modified file, it works fine. 
    // I suspect that there might be some issue with the original file 
    // that prevents it from being read properly. 
    // However, the error message does not provide enough information 
    // for me to pinpoint the exact cause of the problem.
    let filename = String::from("docx-rs01.docx");
    let contents = read_file_contents(&filename).unwrap();
    let docx = docx_rs::read_docx(&contents).unwrap();

    Ok(docx)
}

pub fn read_file_contents(filename: &str) -> Result<Vec<u8>, std::io::Error> {
    let mut contents  = vec![];
    // let mut f = File::open(filename)?;
    let mut f: File = File::open(filename)?;

    let size = f.read_to_end(&mut contents).unwrap();
    println!("size: {}", size);
    Ok(contents)
}

And Then, the error log

> RUST_BACKTRACE=full cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/docx`
size: 666042
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: NumError(ParseIntError { kind: InvalidDigit })', src/main.rs:16:46
stack backtrace:
   0:     0x55c2fa128ae1 - std::backtrace_rs::backtrace::libunwind::trace::he648b5c8dd376705
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x55c2fa128ae1 - std::backtrace_rs::backtrace::trace_unsynchronized::h5da3e203eef39e9f
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x55c2fa128ae1 - std::sys_common::backtrace::_print_fmt::h8d28d3f20588ae4c
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x55c2fa128ae1 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd9a5b0c9c6b058c0
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x55c2fa1501ef - core::fmt::rt::Argument::fmt::h0afc04119f252b53
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/fmt/rt.rs:138:9
   5:     0x55c2fa1501ef - core::fmt::write::h50b1b3e73851a6fe
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/fmt/mod.rs:1094:21
   6:     0x55c2fa126167 - std::io::Write::write_fmt::h184eaf275e4484f0
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/io/mod.rs:1714:15
   7:     0x55c2fa1288f5 - std::sys_common::backtrace::_print::hf58c3a5a25090e71
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x55c2fa1288f5 - std::sys_common::backtrace::print::hb9cf0a7c7f077819
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x55c2fa129e23 - std::panicking::default_hook::{{closure}}::h066adb2e3f3e2c07
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:269:22
  10:     0x55c2fa129bb4 - std::panicking::default_hook::h277fa2776900ff14
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:288:9
  11:     0x55c2fa12a3a9 - std::panicking::rust_panic_with_hook::hceaf38da6d9db792
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:705:13
  12:     0x55c2fa12a2a7 - std::panicking::begin_panic_handler::{{closure}}::h2bce3ed2516af7df
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:597:13
  13:     0x55c2fa128f46 - std::sys_common::backtrace::__rust_end_short_backtrace::h090f3faf8f98a395
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:151:18
  14:     0x55c2fa129ff2 - rust_begin_unwind
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:593:5
  15:     0x55c2f9d5e813 - core::panicking::panic_fmt::h4ec8274704d163a3
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panicking.rs:67:14
  16:     0x55c2f9d5eda3 - core::result::unwrap_failed::h170bc2721a6c6ff2
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/result.rs:1651:5
  17:     0x55c2f9d5f1f6 - core::result::Result<T,E>::unwrap::he5e2a27e7ecab222
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/result.rs:1076:23
  18:     0x55c2f9d5f4ae - docx::hello_docx::he7c9326a24b51d85
                               at /home/ice/projects/gino/ginodocx/docx/src/main.rs:16:16
  19:     0x55c2f9d5f268 - docx::main::hd6500f5418777136
                               at /home/ice/projects/gino/ginodocx/docx/src/main.rs:6:16
  20:     0x55c2f9d5fb8b - core::ops::function::FnOnce::call_once::h0d7c07ebf870a78a
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ops/function.rs:250:5
  21:     0x55c2f9d5f96e - std::sys_common::backtrace::__rust_begin_short_backtrace::hedf86b2bde00af48
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/sys_common/backtrace.rs:135:18
  22:     0x55c2f9d5f941 - std::rt::lang_start::{{closure}}::h9ad352a056f790f6
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/rt.rs:166:18
  23:     0x55c2fa122e7b - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h75ba4244a1c7bb54
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ops/function.rs:284:13
  24:     0x55c2fa122e7b - std::panicking::try::do_call::h0a2baa36dea975a1
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:500:40
  25:     0x55c2fa122e7b - std::panicking::try::h0e42aa233d4224d4
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:464:19
  26:     0x55c2fa122e7b - std::panic::catch_unwind::hefdfd8f482606434
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panic.rs:142:14
  27:     0x55c2fa122e7b - std::rt::lang_start_internal::{{closure}}::h457959f0f91da23b
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/rt.rs:148:48
  28:     0x55c2fa122e7b - std::panicking::try::do_call::h112cfd1acb38183b
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:500:40
  29:     0x55c2fa122e7b - std::panicking::try::ha64f15b20cec18ca
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:464:19
  30:     0x55c2fa122e7b - std::panic::catch_unwind::hbacc2b68ee2c119e
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panic.rs:142:14
  31:     0x55c2fa122e7b - std::rt::lang_start_internal::h5f408694586c2a05
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/rt.rs:148:20
  32:     0x55c2f9d5f91a - std::rt::lang_start::hc3d2ea738feb8cee
                               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/rt.rs:165:17
  33:     0x55c2f9d5f7ee - main
  34:     0x7fe582223510 - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  35:     0x7fe5822235c9 - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:381:3
  36:     0x55c2f9d5f0a5 - _start
  37:                0x0 - <unknown>

A clear and concise description of what the bug is.

Reproduced step

Steps to reproduce the behavior:

RUST_BACKTRACE=full cargo run

Expected behavior

read the docx file well

Actual behavior

thread 'main' panicked at 'called Result::unwrap() on an Err value: NumError(ParseIntError { kind: InvalidDigit })', src/main.rs:16:46

  • OS: [e.g. iOS]
    Linux version 6.2.0-35-generic (buildd@bos03-amd64-016) (x86_64-linux-gnu-gcc-11 (Ubuntu 11.4.0-1ubuntu122.04) 11.4.0, GNU ld (GNU Binutils for Ubuntu) 2.38) fix: add abstract numbering and numbering #3522.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Oct 6 10:23:26 UTC 2

  • Version [e.g. 22]
    rustc 1.72.0 (5680fa18f 2023-08-23)
    cargo 1.72.0 (103a7ff2e 2023-08-15)
    Cargo.toml

[package]
name = "docx"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
docx-rs = "0.4.7"
@TonyMistark TonyMistark added the bug Something isn't working label Nov 1, 2023
@TonyMistark
Copy link
Author

Great news!

There is already a pull request that fixes this bug. #35 I hope it gets published on crates.io soon.

It's work well:

Cargo.toml

[package]
name = "docx"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
# docx-rs = "0.4.7"
docx-rs = { git = "https://github.com/bokuweb/docx-rs", branch = "main" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant