becheran/mlc

`.mlc.toml` options are not used

Closed this issue · 12 comments

The file is read correctly:

mlc/src/cli.rs

Lines 14 to 20 in 377d20f

let mut opt: OptionalConfig = match fs::read_to_string(CONFIG_FILE_PATH) {
Ok(content) => match toml::from_str(&content) {
Ok(o) => o,
Err(err) => panic!("Invalid TOML file {:?}", err),
},
Err(_) => OptionalConfig::default(),
};

I do get an error as expected with a bad TOML file passed in, but the settings are then not respected by the command. I suspect it's simply overridden by the opt var getting clobbered by nothing passed into the cli ars?

@nukemandan I don't fully understand what you tried to do and what did not work?

You passed an invalid TOML file to mlc? Then the expected behavior would be a panic with no further actions.

You did not pass a TOML file? The expected behavior is to use default config variables if they are not overriden by the CLI args.

See how I invoke here: https://github.com/Polkadot-Blockchain-Academy/pba-book/blob/3dd5f5e087cf2250fe3a90d0e1722c629fbc3c35/Makefile.toml#L175-L185

When I run without flags set, I would expect https://github.com/Polkadot-Blockchain-Academy/pba-book/blob/main/.mlc.toml to be picked up, but I cannot seem to get the settings working from the config file no matter the variations I try on the command, from the TLD of the repo.

@nukemandan that is unexpected. Just coppied your config on my lokal setup and there I don't have the issue. When I set debug to true I get the following (expected) output:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+                                                          +
+            markup link checker - mlc v0.16.2             +
+                                                          +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

19:51:41 [DEBUG] (1) mlc::logger: Initialized logging
19:51:41 [INFO] Config:
Debug: true
Dir: .\
Types: ["Markdown", "Html"]
Offline: false
MatchExt: true
RootDir: ./content/
IgnoreLinks: *slides.md,*slides.html,*twitter.com*,*sec.gov*,*support.giphy.com*,*bitdefender.com*,*etherscan.io*,*cryptoslate.com*,*golden.com*,
IgnorePath: [""]
Throttle: 0 ms

On what system are you trying to execute mlc? Linux? What distro? Could you please run it with --debug and see if there is anything interesting in the logs?

Here is some output on my end

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+                                                          +
+            markup link checker - mlc v0.16.2             +
+                                                          +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

17:01:43 [DEBUG] (1) mlc::logger: Initialized logging
17:01:43 [INFO] Config:
Debug: true
Dir: ./
Types: ["Markdown", "Html"]
Offline: false
MatchExt: true
RootDir: ./content/
IgnoreLinks: *slides.md,*slides.html,*twitter.com*,*sec.gov*,*support.giphy.com*,*bitdefender.com*,*etherscan.io*,*cryptoslate.com*,*golden.com*,
IgnorePath: [""]
Throttle: 0 ms
17:01:43 [INFO] Search for files of markup types '[Markdown, Html]' in directory '"./"'
17:01:43 [DEBUG] (1) mlc::file_traversal: Found file: MarkupFile { markup_type: Markdown, path: "./content/polkadot/data-sharding/page.md" }.
17:01:43 [DEBUG] (1) mlc::file_traversal: Found file: MarkupFile { markup_type: Markdown, path: "./content/polkadot/data-sharding/slides.md" }.

As you can see, the root dir is ignored, and the current working dir is used. I think that is the real bug here.

minimal example of the issue:

# from path with .mlc.toml in it:
# Overwrites the config for IgnoreLinks of the config file. Works as expected, skipping a dead link
mlc --debug content/xcm/config/page.md -i "*slides.html" | tee mlc.log

# Although IgnoreLinks in the debug is correctly set, errors
mlc --debug content/xcm/config/page.md | tee mlc.log
mlc --debug content/xcm/config/page.md | tee mlc.log

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+                                                          +
+            markup link checker - mlc v0.16.2             +
+                                                          +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

22:52:04 [DEBUG] (1) mlc::logger: Initialized logging
22:52:04 [INFO] Config:
Debug: true
Dir: content/xcm/config/page.md
Types: ["Markdown", "Html"]
Offline: false
MatchExt: true
RootDir: ./content/
IgnoreLinks: *slides.md,*slides.html,*twitter.com*,*sec.gov*,*support.giphy.com*,*bitdefender.com*,*etherscan.io*,*cryptoslate.com*,*golden.com*,
IgnorePath: [""]
Throttle: 0 ms
22:52:04 [INFO] Search for files of markup types '[Markdown, Html]' in directory '"content/xcm/config/page.md"'
22:52:04 [DEBUG] (1) mlc::file_traversal: Found file: MarkupFile { markup_type: Markdown, path: "content/xcm/config/page.md" }.
22:52:04 [INFO] Scan file at path 'content/xcm/config/page.md' for links.
22:52:04 [WARN] Strip everything after #. The chapter part '#-how-to-use-revealjs-slides' is not checked.
22:52:04 [DEBUG] (1) mlc::link_validator::file_system: Check file system link target "../../contribute/how-to/page.md#-how-to-use-revealjs-slides"
22:52:04 [DEBUG] (1) mlc::link_validator::file_system: Check file system link target "slides.html"
22:52:04 [WARN] Strip everything after #. The chapter part '#top' is not checked.
22:52:04 [DEBUG] (1) mlc::link_validator::file_system: Check file system link target "#top"
22:52:04 [INFO] Throttle HTTP requests to same host: false
22:52:04 [INFO] Check link /home/nuke/git/book/content/xcm/config/../../contribute/how-to/page.md.
22:52:04 [DEBUG] (1) mlc::link_validator::file_system: Absolute target path Path { inner: "/home/nuke/git/book/content/xcm/config/../../contribute/how-to/page.md" }
22:52:04 [INFO] Check link /home/nuke/git/book/content/xcm/config/.
22:52:04 [DEBUG] (1) mlc::link_validator::file_system: Absolute target path Path { inner: "/home/nuke/git/book/content/xcm/config/" }
22:52:04 [INFO] Check link /home/nuke/git/book/content/xcm/config/slides.html.
22:52:04 [DEBUG] (1) mlc::link_validator::file_system: Absolute target path Path { inner: "/home/nuke/git/book/content/xcm/config/slides.html" }
[ OK ] content/xcm/config/page.md (7, 1) => ../../contribute/how-to/page.md#-how-to-use-revealjs-slides -
[Err ] content/xcm/config/page.md (8, 1) => slides.html - Target filename not found.[ OK ] content/xcm/config/page.md (16, 1) => #top -


Result (3 links):


OK       2
Skipped  0
Warnings 0
Errors   1

The following links could not be resolved:

content/xcm/config/page.md (8, 1) => slides.html

@nukemandan reading your comments in the PR #80, can this issue be closed? Do you have a solution for your problem?

learned the hard way to RTFM 😜 sorry about that!

Sadly no, the last comment details what I still think is a bug. [Err ] content/xcm/config/page.md (8, 1) => slides.html - Target filename not found.[ OK ] content/xcm/config/page.md (16, 1) => #top - here I have explicitly stated to ignore this link in any file, but the error comes up only for the config file, not if set in the cli agrs.

@nukemandan I don't really know what the bug is? Can you provide me a minimal working example of what is not working with the toml file, but does work without it?

It is hard for me to reproduce since I don't see any differences once the file is parsed correctley (which you would see in the debug logs). Then the same config struct is used to run the code and it should always produce the same results.

So here is perhaps one: https://github.com/Cryptorado-Community/cryptorado-rs/pull/4/files#diff-001bc7edd34a2a3d34d6220d949af7ef1f2dd2818303d04c2a7cdab9c708bb7cR8

I want to ignore the output of cargo doc and set target to be explicitly ignored. Yet in any rust project I run with this minimal setting in .mlc.toml in the project root, I have mlc checking the rustdocs built. I can get the right behavior with the CLI flag set mlc --ignore-path target

Any chance you have a rust project with with mlc configured and built rustdocs? See it's it's just me 😭 (thanks for the support btw!)

@nuke-web3 so sorry that I forgot about the issue. I just tried it again and could reproduce it. Will provide a fix ASAP..

Fixed with version 0.17.1

Much better late than never! just getting back to using this great to of your in https://github.com/nuke-web3/book/ and really loving what it can do for local & CI driven checks 🌟

Appreciate you!