Skip to content

Conversation

@lionel-
Copy link
Contributor

@lionel- lionel- commented Jan 29, 2026

Addresses posit-dev/positron#11591

I had actually fixed this in #1003 by adding (what I thought was) a new as_label() function extracted from rlang:

as_label <- function(x) {

Turns out, there was already a much more bare bones as_label() in the repo:

as_label <- function(expr) {

Here's the thing:

  • When loading the R files from disk, as happens in a debug build, the new as_label() overwrote the old one. So my new implementation was working as expected.

  • When loading the R files from the binary blob, as happens in a release build, rust-embed loads the files alphabetically (https://docs.rs/crate/rust-embed-utils/8.11.0/source/src/lib.rs#19), and the new impl gets overwritten by the old one!

This had me very confused for a while!


This PR removes the dangling as_label(), and adjusts the modules loading mechanism to match rust-embed so this doesn't happen again in the future.

@lionel- lionel- requested a review from DavisVaughan January 29, 2026 11:45
Comment on lines 272 to 286
// Collect and sort entries alphabetically to match RustEmbed iteration order.
// https://github.com/posit-dev/positron/issues/11591#issuecomment-3816838107
let mut entries: Vec<_> = std::fs::read_dir(directory)?
.filter_map(|entry| match entry {
Ok(entry) => Some(entry),
Err(err) => {
log::error!("Can't read directory entry: {err:?}");
None
},
})
.collect();
entries.sort_by_key(|entry| entry.path());

for entry in entries {
match entry {
Ok(entry) => import_file(&entry.path(), src, env)?,
Err(err) => log::error!("Can't load modules from file: {err:?}"),
};
import_file(&entry.path(), src, env)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

We've got a mix of ? and log + continue style behavior here

The modules feel very important to me, I wonder if log::error!("Can't read directory entry: {err:?}") should really be turned into a ? that propagates upwards rather than logging + continue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm I think I agree with your sentiment that we're currently too lenient in our init routine.

I've implemented your suggestion and turned the upstream logging into a loud panic. Note that this only concerns the debug path for local module files. We're still lenient in release builds, we should probably fail early there too. WDYT?

Also note that the hot-reloading path still only logs, otherwise we'd get panic for things like syntax errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

We're still lenient in release builds, we should probably fail early there too.

I do agree that even in release builds we should probably fail loudly as long as its fairly informative logging.

Modules just feel so critical to ark working, that a loud panic feels right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We now panic consistently if modules fail to load or initialise.

Comment on lines 272 to 286
// Collect and sort entries alphabetically to match RustEmbed iteration order.
// https://github.com/posit-dev/positron/issues/11591#issuecomment-3816838107
let mut entries: Vec<_> = std::fs::read_dir(directory)?
.filter_map(|entry| match entry {
Ok(entry) => Some(entry),
Err(err) => {
log::error!("Can't read directory entry: {err:?}");
None
},
})
.collect();
entries.sort_by_key(|entry| entry.path());

for entry in entries {
match entry {
Ok(entry) => import_file(&entry.path(), src, env)?,
Err(err) => log::error!("Can't load modules from file: {err:?}"),
};
import_file(&entry.path(), src, env)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

We're still lenient in release builds, we should probably fail early there too.

I do agree that even in release builds we should probably fail loudly as long as its fairly informative logging.

Modules just feel so critical to ark working, that a loud panic feels right?

@lionel- lionel- force-pushed the bugfix/non-srcref-labels branch from 9345c3b to 04fa753 Compare February 3, 2026 18:49
@lionel- lionel- force-pushed the bugfix/non-srcref-labels branch from 04fa753 to 29e7fa8 Compare February 3, 2026 18:49
@lionel- lionel- merged commit 08a3bb5 into main Feb 3, 2026
8 checks passed
@lionel- lionel- deleted the bugfix/non-srcref-labels branch February 3, 2026 18:54
@github-actions github-actions bot locked and limited conversation to collaborators Feb 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants