Skip to content

Commit e53ab84

Browse files
committed
add catch and update error message
1 parent 76361a8 commit e53ab84

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

source/loader/layers/sanitizer/asan_options.hpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ struct AsanOptions {
4242

4343
private:
4444
AsanOptions(logger::Logger &logger) {
45-
auto OptionsEnvMap = getenv_to_map("UR_LAYER_ASAN_OPTIONS");
45+
std::optional<EnvVarMap> OptionsEnvMap;
46+
try {
47+
OptionsEnvMap = getenv_to_map("UR_LAYER_ASAN_OPTIONS");
48+
} catch (const std::invalid_argument &e) {
49+
logger.error(e.what());
50+
die("Sanitizer failed to parse options.\n");
51+
}
52+
4653
if (!OptionsEnvMap.has_value()) {
4754
return;
4855
}
@@ -74,8 +81,8 @@ struct AsanOptions {
7481
Opt = false;
7582
} else {
7683
std::stringstream SS;
77-
SS << "<SANITIZER>[ERROR]: \"" << Name << "\" is set to \""
78-
<< Value << "\", which is not an valid setting. ";
84+
SS << "\"" << Name << "\" is set to \"" << Value
85+
<< "\", which is not an valid setting. ";
7986
SS << "Acceptable input are: for enable, use:";
8087
for (auto &S : TrueStrings) {
8188
SS << " \"" << S << "\"";
@@ -86,7 +93,8 @@ struct AsanOptions {
8693
SS << " \"" << S << "\"";
8794
}
8895
SS << ".";
89-
die(SS.str().c_str());
96+
logger.error(SS.str().c_str());
97+
die("Sanitizer failed to parse options.\n");
9098
}
9199
}
92100
};
@@ -106,9 +114,10 @@ struct AsanOptions {
106114
}
107115
MaxQuarantineSizeMB = temp_long;
108116
} catch (...) {
109-
die("<SANITIZER>[ERROR]: \"quarantine_size_mb\" should be "
110-
"an positive integer that smaller than or equal to "
111-
"4294967295.");
117+
logger.error("\"quarantine_size_mb\" should be "
118+
"an integer in range[0, {}].",
119+
UINT32_MAX);
120+
die("Sanitizer failed to parse options.\n");
112121
}
113122
}
114123

@@ -120,10 +129,11 @@ struct AsanOptions {
120129
if (MinRZSize < 16) {
121130
MinRZSize = 16;
122131
logger.warning("Trying to set redzone size to a "
123-
"value less than 16 is ignored");
132+
"value less than 16 is ignored.");
124133
}
125134
} catch (...) {
126-
die("<SANITIZER>[ERROR]: \"redzone\" should be an integer");
135+
logger.error("\"redzone\" should be an integer in range[0, 16].");
136+
die("Sanitizer failed to parse options.\n");
127137
}
128138
}
129139

@@ -135,10 +145,12 @@ struct AsanOptions {
135145
if (MaxRZSize > 2048) {
136146
MaxRZSize = 2048;
137147
logger.warning("Trying to set max redzone size to a "
138-
"value greater than 2048 is ignored");
148+
"value greater than 2048 is ignored.");
139149
}
140150
} catch (...) {
141-
die("<SANITIZER>[ERROR]: \"max_redzone\" should be an integer");
151+
logger.error(
152+
"\"max_redzone\" should be an integer in range[0, 2048].");
153+
die("Sanitizer failed to parse options.\n");
142154
}
143155
}
144156
}

0 commit comments

Comments
 (0)