dfinity / dfinity/sdk

I see only a part of `Debug.print` messages for an one-way function

Open
#4,041 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs-triage
Dominant language
Rust
Stars
204
Forks
98
PR merge metrics
No merged PRs in 30d

Description

Code like this does not print the value of the exception:

    public shared({caller}) func installPackageWrapper({ // TODO: Rename.
        whatToInstall: {
            #package;
            #simplyModules : [(Text, Common.SharedModule)];
        };
        repo: Common.RepositoryPartitionRO;
        pmPrincipal: Principal;
        packageName: Common.PackageName;
        version: Common.Version;
        installationId: Common.InstallationId;
        preinstalledModules: [(Text, Principal)];
        user: Principal;
    }): () {
        try {
            Debug.print("R1");
            onlyOwner(caller, "installPackageWrapper");
            ...
            Debug.print("R2: " # debug_show(Iter.toArray(preinstalled2.entries())));
            // Throws an exception:
            let ?backend = preinstalled2.get("backend") else { // FIXME
                Debug.trap("error 1");
            };
            ...
            Debug.print("R3");
            ...
        };
        catch (e) {
            Debug.print("ONE installPackageWrapper");
            Debug.print("installPackageWrapper: " # Error.message(e));
        };
    };

Actually, it prints:

2024-12-15 16:53:47.297878369 UTC: [Canister 6cvy2-omaaa-aaaaa-qackq-cai] R1
2024-12-15 16:53:47.297878369 UTC: [Canister 6cvy2-omaaa-aaaaa-qackq-cai] R2: []
$ dfx --version
dfx 0.24.0

Apparently, we don't see messages printed by an one-way function produces by it right before its exit. This severely complicates debugging.

Sadly, to give you a repeatable bug code, I would need to disclose my closed source. Even if I did disclose it, to reprise the bug, need to follow a relatively complex GUI procedure, so it is not repeatable automatically.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported dfx 0.24.0 behavior and the Motoko installPackageWrapper example, focusing on logging immediately before a one-way function exits and on the catch block's Error.message output. Reproduce the missing Debug.print output with a minimal case if possible; done means the relevant messages are emitted reliably and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.