ModFS error codes#1311
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughModFS now defines structured error codes, increases storage limits, and adds error-code out parameters across native APIs. Lua bindings return operation results together with numeric error codes and expose 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/pc/mods/mod_fs.cpp (1)
1104-1116:⚠️ Potential issue | 🟠 Major | ⚡ Quick winDefer
totalSizemutation until copy actually succeeds.
modFs->totalSizeis updated before allocation/create-file steps complete. If later steps fail, size accounting stays mutated and can block valid future writes.💡 Suggested fix
- modFs->totalSize = newTotalSize; - // copy file u8 *buffer = (u8 *) malloc(srcfile->size); if (!buffer) { ... return false; } @@ memcpy(dstfile->filepath, ...); ... dstfile->offset = 0; + modFs->totalSize = newTotalSize; return true;Also applies to: 1129-1133
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/pc/mods/mod_fs.cpp` around lines 1104 - 1116, The code updates modFs->totalSize before the copy/creation actually succeeds; change the logic so newTotalSize is computed and validated but modFs->totalSize is not assigned until after the file allocation/create and all subsequent steps complete successfully (i.e., move the assignment modFs->totalSize = newTotalSize to the end of the successful copy path and, for any code paths that can fail after allocation, either perform the assignment only after those checks or roll back the allocation and leave modFs->totalSize unchanged); apply the same change to the second identical site that updates totalSize (the block using newTotalSize and modFs->totalSize around the other copy/create sequence).
🧹 Nitpick comments (1)
src/pc/mods/mod_fs.h (1)
36-36: 💤 Low valueClarify the comment wording for readability.
The phrase "not ascii" in a comma-separated list reads ambiguously. Consider rewording:
- MOD_FS_ERR_FILEPATH_INVALID_CHAR, // Filepath contains invalid characters (not ascii, control, star or backslash) + MOD_FS_ERR_FILEPATH_INVALID_CHAR, // Filepath contains invalid characters (non-ASCII, control characters, asterisks, or backslashes)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/pc/mods/mod_fs.h` at line 36, The comment for the enum value MOD_FS_ERR_FILEPATH_INVALID_CHAR is ambiguous — reword it to list the invalid character classes clearly (e.g., "Filepath contains invalid characters (non-ASCII, control characters, '*' or '\\')") so readers unambiguously understand which characters are disallowed; update the comment on MOD_FS_ERR_FILEPATH_INVALID_CHAR accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/pc/mods/mod_fs.cpp`:
- Around line 1050-1065: Guard against identical source and destination paths
before performing overwrite/delete logic: in the code paths that call
modfs::mod_fs_get_file(modFs, newpath, err) and potentially call
modfs::mod_fs_delete_file(modFs, newpath, err) (the blocks that later
snprintf(oldfile->filepath, ...) and return true), add an early check comparing
the current file path (oldfile->filepath) to newpath (e.g.,
strcmp(oldfile->filepath, newpath) == 0) and return true immediately if they are
identical; do this before any deletion/overwrite is attempted so you never
delete/free the same object being moved/copied (apply the same check in both
occurrences where mod_fs_get_file/mod_fs_delete_file and
snprintf(oldfile->filepath, ...) are used).
- Around line 777-786: The function mod_fs_file_check_parameter is narrowing
inputs by declaring parameter, parameterMin, and parameterMax as u8 so values
>=256 wrap and bypass validation; change those three parameters to a
sufficiently wide unsigned type (e.g., unsigned int or uint32_t) in the
mod_fs_file_check_parameter declaration and definition and update every call
site that passes values (from callers interacting with ModFsFile) to pass the
wider type; keep the error reporting via mod_fs_raise_error and parameterName
as-is but ensure formatting specifiers (%u) match the chosen wider type.
---
Outside diff comments:
In `@src/pc/mods/mod_fs.cpp`:
- Around line 1104-1116: The code updates modFs->totalSize before the
copy/creation actually succeeds; change the logic so newTotalSize is computed
and validated but modFs->totalSize is not assigned until after the file
allocation/create and all subsequent steps complete successfully (i.e., move the
assignment modFs->totalSize = newTotalSize to the end of the successful copy
path and, for any code paths that can fail after allocation, either perform the
assignment only after those checks or roll back the allocation and leave
modFs->totalSize unchanged); apply the same change to the second identical site
that updates totalSize (the block using newTotalSize and modFs->totalSize around
the other copy/create sequence).
---
Nitpick comments:
In `@src/pc/mods/mod_fs.h`:
- Line 36: The comment for the enum value MOD_FS_ERR_FILEPATH_INVALID_CHAR is
ambiguous — reword it to list the invalid character classes clearly (e.g.,
"Filepath contains invalid characters (non-ASCII, control characters, '*' or
'\\')") so readers unambiguously understand which characters are disallowed;
update the comment on MOD_FS_ERR_FILEPATH_INVALID_CHAR accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: cea03efa-590e-4739-a870-77a9195a2cc7
📒 Files selected for processing (13)
autogen/convert_functions.pyautogen/convert_structs.pyautogen/lua_definitions/constants.luaautogen/lua_definitions/functions.luaautogen/lua_definitions/structs.luadocs/lua/constants.mddocs/lua/functions-5.mddocs/lua/functions.mddocs/lua/guides/modfs.mdsrc/pc/lua/smlua_constants_autogen.csrc/pc/lua/smlua_functions_autogen.csrc/pc/mods/mod_fs.cppsrc/pc/mods/mod_fs.h
|
This is peak, i approve |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
autogen/convert_structs.py (1)
480-480: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valuePrefer the already-extracted
is_c_arrayvariable overfield['is_c_array'].Line 440 already destructures
is_c_arrayfromget_struct_field_info(), which usesfield.get('is_c_array', False)defensively. Line 480 bypasses this by accessingfield['is_c_array']directly, creating an inconsistency that could raiseKeyErrorif a future code path constructs fields without going throughparse_struct.♻️ Use the destructured variable
- if field['is_c_array']: + if is_c_array: row.append('true')🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@autogen/convert_structs.py` at line 480, In the relevant struct-field conversion logic, replace the direct field['is_c_array'] lookup with the already-destructured is_c_array variable from get_struct_field_info(), preserving the defensive default behavior for fields that omit this key.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@autogen/convert_structs.py`:
- Line 480: In the relevant struct-field conversion logic, replace the direct
field['is_c_array'] lookup with the already-destructured is_c_array variable
from get_struct_field_info(), preserving the defensive default behavior for
fields that omit this key.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 231a2026-b0cd-4252-b42f-2599909abd17
📒 Files selected for processing (9)
autogen/convert_structs.pyautogen/lua_definitions/constants.luaautogen/lua_definitions/functions.luaautogen/lua_definitions/structs.luadocs/lua/constants.mddocs/lua/functions-5.mddocs/lua/functions.mdsrc/pc/lua/smlua_constants_autogen.csrc/pc/lua/smlua_functions_autogen.c
💤 Files with no reviewable changes (1)
- docs/lua/functions-5.md
✅ Files skipped from review due to trivial changes (2)
- docs/lua/functions.md
- autogen/lua_definitions/structs.lua
🚧 Files skipped from review as they are similar to previous changes (4)
- docs/lua/constants.md
- src/pc/lua/smlua_constants_autogen.c
- autogen/lua_definitions/constants.lua
- autogen/lua_definitions/functions.lua
Suggested a while ago by @kermeow
Adds error codes to all
ModFSfunctions to identify errors more easily.Error code is returned as second return value:
Additionally:
No, Luigi, before you ask, I didn't remove extensions, and I don't plan to