Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace StackErrorPtr in filesystem by exceptions #506

Merged
merged 4 commits into from
Aug 2, 2022

Conversation

asuessenbach
Copy link
Contributor

@asuessenbach asuessenbach commented Jul 27, 2022

Description

This PR shows how exceptions could be used in the new framework -> see #505.

All functions in vfs/filesystem.hpp that previously returned a StackErrorPtr have been changed to throw an exception on failure.
Besides that, the non-modifying functions have been marked as const, and some enumeration functions have been moved from RootFileSystem to FileSystem.

Note that

  • in order to get the virtual_file_system_tests succeed, I had to manually adjust the base path cwd in default.cpp. That test failed in my environment even before any of my changes.
  • all test were done on Windows; android_aasset_manager.cpp is just edited, not compiled.

@asuessenbach asuessenbach marked this pull request as ready for review July 27, 2022 08:05
@TomAtkinsonArm
Copy link
Contributor

Looking at the test cases this has convinced me that this is the way to go!

Shall we merge #495 and then address your further comments either here or in smaller PRs? If the tests pass here i'm happy for this to be merged on top of 495 :)

StackErrorPtr enumerate_files(const std::string &file_path, const std::string &extension, std::vector<std::string> *files);
StackErrorPtr enumerate_files_recursive(const std::string &file_path, const std::string &extension, std::vector<std::string> *files);
StackErrorPtr enumerate_folders_recursive(const std::string &file_path, std::vector<std::string> *folders);
virtual bool folder_exists(const std::string &folder_path) const override;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a small thing. But worth pointing out should keep override and remove virtual.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is mainly my fault. Although its not needed, i've gotten into the habit of adding virtual to all virtual functions. We should address this in a new PR for the entire branch.

{
if (!asset_manager)
{
return 0;
throw std::runtime_error("vfs/android_aasset_manager.cpp line" + std::to_string(__LINE__) + "AAsset Manager not initialized");
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to make this a macro and use something like:
#define ERROR_STR(...) (( FILE ":" LINE " " VA_ARGS))

Something to make the repeated tasks like listing out the file name a little less required and only capture the actual error response is what I'm looking for. Can change the above as needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be addressed in a new PR, I will create an issue to follow up on this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a fan of having the filename hard-wired like this. When someone wants to change the filename at some point in the future, it's going to be a little irritating to have to change all these too.

FILE seems like a perfectly reasonable thing to use here, and hiding that inside a macro seems fine to me. If you really don't want the full path to appear in the output then maybe do some processing on the path to strip the front off.

@gpx1000
Copy link
Contributor

gpx1000 commented Jul 29, 2022

I like this direction on the whole. I think it's good to take this after #495

@TomAtkinsonArm TomAtkinsonArm changed the title Proof of concept: replace StackErrorPtr in filesystem by exceptions Replace StackErrorPtr in filesystem by exceptions Jul 29, 2022
TomAtkinsonArm and others added 4 commits August 1, 2022 17:49
more tests and fixes

recursive tests

more tests

remove order specific checks from tests

review comments
Note that android_aasset_manager.cpp is just edited, not compiled!
@TomAtkinsonArm
Copy link
Contributor

Merged! issues can be addressed in later PRs see #505

@TomAtkinsonArm TomAtkinsonArm merged commit f96061a into KhronosGroup:framework/v2.0 Aug 2, 2022
@asuessenbach asuessenbach deleted the exceptions branch August 2, 2022 10:11
TomAtkinsonArm added a commit to TomAtkinsonArm/Vulkan-Samples that referenced this pull request Nov 21, 2022
* std filesystem

more tests and fixes

recursive tests

more tests

remove order specific checks from tests

review comments

* fix duplicated check

* review changes

* Replace StackErrorPtr in vfs/filesystem.hpp by exceptions.

Note that android_aasset_manager.cpp is just edited, not compiled!

Co-authored-by: Thomas Atkinson <thomas.atkinson@arm.com>
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.

None yet

4 participants