Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/OpenColorIO/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <vector>
#include <regex>
#include <functional>
#include <filesystem>

#include <pystring.h>

Expand Down Expand Up @@ -1155,7 +1156,7 @@ ConstConfigRcPtr Config::CreateFromFile(const char * filename)
{
if (!filename || !*filename)
{
throw ExceptionMissingFile ("The config filepath is missing.");
throw ExceptionMissingFile("The config filepath is missing.");
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.

Probably OK for now, but it is worth noting that as you highlighted in the issue this condition isn't quite the same as a missing file. ideally we'd have a different type for this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed! Though should I switch this to just OCIO::Exception for now then? Ultimately it's a runtime error so it kind of fits!

}

// Check for URI Pattern: ocio://<config name>
Expand All @@ -1167,6 +1168,13 @@ ConstConfigRcPtr Config::CreateFromFile(const char * filename)
return CreateFromBuiltinConfig(uri.c_str());
}

if (!std::filesystem::exists(filename))
{
std::ostringstream oss;
oss << "'" << filename << "' file does not exist.";
throw ExceptionMissingFile(oss.str().c_str());
}

std::ifstream ifstream = Platform::CreateInputFileStream(
filename,
std::ios_base::in | std::ios_base::binary
Expand Down
4 changes: 2 additions & 2 deletions tests/cpu/builtinconfigs/BuiltinConfig_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ OCIO_ADD_TEST(BuiltinConfigs, create_builtin_config)
// Test that CreateFromFile does not work without ocio:// prefix for built-in config.
OCIO_CHECK_THROW_WHAT(
OCIO::Config::CreateFromFile("cg-config-v1.0.0_aces-v1.3_ocio-v2.1"),
OCIO::Exception,
"Error could not read 'cg-config-v1.0.0_aces-v1.3_ocio-v2.1' OCIO profile."
OCIO::ExceptionMissingFile,
"'cg-config-v1.0.0_aces-v1.3_ocio-v2.1' file does not exist."
);

{
Expand Down
2 changes: 1 addition & 1 deletion tests/python/ConfigTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ def testFromEnvAndFromFile(uri, numberOfExpectedColorspaces, expectedConfigName)
nbOfColorspacesForStudioConfig = 55

# Test that CreateFromFile does not work without ocio:// prefix for built-in config.
with self.assertRaises(OCIO.Exception) as cm:
with self.assertRaises(OCIO.ExceptionMissingFile) as cm:
OCIO.Config.CreateFromFile(cgConfigName)

# Test CG config.
Expand Down