trustgraph icon indicating copy to clipboard operation
trustgraph copied to clipboard

Bare except on os.mkdir in load_sample_documents

Open cybermaggedon opened this issue 6 months ago • 4 comments

Description

In trustgraph-cli/trustgraph/cli/load_sample_documents.py (lines 31–34):

try:
    os.mkdir("doc-cache")
except:
    pass

Problem

The intent is to ignore "directory already exists", but bare except: also silently swallows permission errors, read-only filesystem errors, and any other OS-level failure. The user gets no feedback when the cache directory can't be created, and the script fails later with a confusing error when it tries to write into the missing directory.

Suggested fix

Please PR against the latest release/vX.Y branch.

os.makedirs("doc-cache", exist_ok=True)

This is a one-line fix. os.makedirs with exist_ok=True handles the "already exists" case and lets real errors (permissions, disk full) propagate naturally.

What you'll learn

How the CLI sample-document loader works, and the difference between os.mkdir and os.makedirs.

cybermaggedon avatar May 07 '26 09:05 cybermaggedon

Fixed by #952.

jmolz avatar May 26 '26 14:05 jmolz

Hey, wanted to pick this up but did a bit of digging at first looks like the os.mkdir("doc-cache") bare-except pattern isn't actually in load_sample_documents.py anymore. Ran git grep -n "mkdir" across the whole repo just to be safe and couldn't find it anywhere. Also noticed PR 899 already had this exact fix (os.makedirs(exist_ok=True)) but it got closed over the CLA, not the code itself. Seems like this got resolved through some other refactor in the meantime.Might be worth closing this one out if that checks out on your end ,happy to help with something else in the meantime if useful.

01AtharvR avatar Jul 13 '26 00:07 01AtharvR

Thanks for checking, @01AtharvR. This was fixed by #952, which merged into release/v2.5. Because that PR targeted a release branch rather than the default branch, GitHub did not automatically close #869. #956 subsequently removed the doc-cache mechanism entirely. @cybermaggedon, this can be closed as completed.

jmolz avatar Jul 13 '26 13:07 jmolz

Thanks for reviewing this @01AtharvR @jmolz 🙏

cybermaggedon avatar Jul 13 '26 13:07 cybermaggedon