Skip to content

[fix]: Scheduler failing on DHIS2 2.43 (userCredentials removed from /me) - #1248

Open
deeonwuli wants to merge 2 commits into
developmentfrom
fix/scheduler-in-2.43
Open

[fix]: Scheduler failing on DHIS2 2.43 (userCredentials removed from /me)#1248
deeonwuli wants to merge 2 commits into
developmentfrom
fix/scheduler-in-2.43

Conversation

@deeonwuli

Copy link
Copy Markdown
Contributor

📌 References

📝 Implementation

Root cause: DHIS2 version 2.43 removed the userCredentials wrapper from /api/me; username/userRoles are now top-level. Code reading currentUser.userCredentials.userRoles/.username threw Cannot read properties of undefined (reading 'userRoles'). In the scheduler this surfaced only as [ERROR] scheduler - {} because the catch blocks serialized the error with JSON.stringify(error), which returns {} for Error objects.

  • Added a getErrorMessage helper (src/utils/error.ts) and used it in the scheduler catch blocks (cli.ts, SchedulerCLI.ts) so errors log with their real message/stack instead of {}. Also applied it to previously swallowed dataStore read errors (StorageDataStoreClient).
  • Updated all current-user (/me) reads to support both pre-2.43 and 2.43+ shapes via a fallback (userCredentials?.x ?? x): permissions.ts (getUserInfo, getUserRoles), UserD2ApiRepository.getCurrent, GenericSyncUseCase, and the package list/import components (routed through the user use case).

📹 Screenshots/Screen capture

🔥 Is there anything the reviewer should know to test it?

  • Run the scheduler against a DHIS2 2.43 instance that has a scheduler-enabled sync rule. Before this change it fails right after "Loading synchronization rules from remote server"; after, rules load and schedule normally.

#869dqwtvv

@bundlemon

bundlemon Bot commented Jun 22, 2026

Copy link
Copy Markdown

BundleMon

No change in files bundle size

Groups updated (1)
Status Path Size Limits
Build Folder
./**/*
2.67MB (+184B +0.01%) +20%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@MiquelAdell
MiquelAdell requested a review from idelcano July 1, 2026 10:25
@MiquelAdell

Copy link
Copy Markdown
Contributor

@idelcano could you please provide a functional review of that one?
thanks!

@MiquelAdell
MiquelAdell removed their request for review July 1, 2026 10:26
@gqcorneby

Copy link
Copy Markdown
Contributor

Hi @deeonwuli! Heads up that this branch is behind development and conflicts with the d2-api upgrade that merged last week (#1064), which touched the same userCredentials handling.

Related PR: #1064

Could you resolve conflicts and give it a quick check on 2.43 before I finalize? Worth a look at #1064 first, there's real overlap, so the scope here likely narrows to the logging improvement. 🙏

@xurxodev xurxodev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deeonwuli @MiquelAdell @gqcorneby

I think this PR is not necessary and it can be closed. The user credentials is a 2.42 problem not 2.43 and it was solved by @MatiasArriola in this PR #1064

@MiquelAdell

Copy link
Copy Markdown
Contributor

thank you all for your comments.
@MatiasArriola can you confirm that this PR #1248 is no longer needed after #1064 ?

@MatiasArriola

Copy link
Copy Markdown
Contributor

thank you all for your comments. @MatiasArriola can you confirm that this PR #1248 is no longer needed after #1064 ?

userCredentials usage was already removed in the referenced PR. But this PR also improves error handling / reporting in the scheduler. Maybe we can still benefit from that part (I guess it surfaced only because of userCredentials-related errors, but will help in the future for any other class of error).

The diff is outdated since this branch needs to incorporate changes from development and resolve the conflicts (which are in fact the previous userCredentials implementation). So if we want to keep part of this PR, it would stop being "Scheduler failing on DHIS2 2.43 (userCredentials removed from /me)" and become something like "Improve error reporting in Scheduler"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants