Refactor colnamesInt to provide context-specific error messages (#5039) #7554
+42
−31
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses issue #5039 by refactoring the internal colnamesInt function at both the C and R levels. By introducing a mandatory source argument, the internal error messages now provide specific context (e.g., pinpointing whether a failure occurred during an on= join, setkey, or frank), making debugging significantly more intuitive for the user.
Technical Changes
src/utils.c: Modified the colnamesInt signature to accept a 5th argument, SEXP source. Updated all internal error() calls to include a %s placeholder, prepending the error with the provided context string.
src/data.table.h: Updated the function prototype to remain in sync with the new signature.
src/init.c: Updated the R-to-C registration from -1 (variable) to a strict 5 to ensure formal argument counting at the C interface level.
R/wrappers.R: Updated the R-side wrapper for colnamesInt to accept source=NULL and pass it through the .Call interface.
Global Refactor: Performed a comprehensive audit and update of 19 call sites across the following files to ensure the new 5th argument is passed correctly with descriptive hints:
R/data.table.R (Joins, setcolorder, setnames)
R/mergelist.R (Merge operations and internal column copying)
R/setkey.R (Key assignment)
R/frank.R (Ranking)
R/duplicated.R (Unique/Duplicated checks)
R/setops.R (Set operations)
Impact
Users will no longer see generic "inscrutable" errors. For example: Old Error: Error in colnamesInt(...) : argument specifying columns received non-existing column(s): cols[2]='z' New Error: Error in colnamesInt(...) : In x table's columns in on= join, argument specifying columns received non-existing column(s): cols[2]='z'
Checklist
[x] Reproduced the original "inscrutable" error.
[x] Successfully compiled using R CMD INSTALL ..
[x] Verified that all 19 call sites are updated to avoid "unused argument" or "argument mismatch" errors.
[x] Passed manual tests for joins, setkeys, and set operations.
Closes #5039