Skip to content

Commit 32a527d

Browse files
authored
Improve panic messages if retrieving/parsing GL_VERSION fails (#331)
* Improve panic messages if retrieving/parsing GL_VERSION fails * Format
1 parent 83c7b9b commit 32a527d

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/web_sys.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,14 @@ impl Context {
253253
let (extensions, supported_extensions) = build_extensions!(context, WebGlRenderingContext);
254254

255255
// Retrieve and parse `GL_VERSION`
256-
let raw_string = context.get_parameter(VERSION).unwrap().as_string().unwrap();
257-
let version = Version::parse(&raw_string).unwrap();
256+
let raw_jsvalue = context
257+
.get_parameter(VERSION)
258+
.expect("context.get_parameter(VERSION) shouldn't throw");
259+
let raw_string = raw_jsvalue
260+
.as_string()
261+
.unwrap_or_else(|| panic!("{:?} should be a string", raw_jsvalue));
262+
let version = Version::parse(&raw_string)
263+
.expect("context.get_parameter(VERSION) should be parseable as an OpenGL version");
258264

259265
Self {
260266
raw: RawRenderingContext::WebGl1(context),
@@ -279,8 +285,14 @@ impl Context {
279285
let (extensions, supported_extensions) = build_extensions!(context, WebGl2RenderingContext);
280286

281287
// Retrieve and parse `GL_VERSION`
282-
let raw_string = context.get_parameter(VERSION).unwrap().as_string().unwrap();
283-
let version = Version::parse(&raw_string).unwrap();
288+
let raw_jsvalue = context
289+
.get_parameter(VERSION)
290+
.expect("context.get_parameter(VERSION) shouldn't throw");
291+
let raw_string = raw_jsvalue
292+
.as_string()
293+
.unwrap_or_else(|| panic!("{:?} should be a string", raw_jsvalue));
294+
let version = Version::parse(&raw_string)
295+
.expect("context.get_parameter(VERSION) should be parseable as an OpenGL version");
284296

285297
Self {
286298
raw: RawRenderingContext::WebGl2(context),

0 commit comments

Comments
 (0)