Skip to content

Commit

Permalink
Improve panic messages if retrieving/parsing GL_VERSION fails (#331)
Browse files Browse the repository at this point in the history
* Improve panic messages if retrieving/parsing GL_VERSION fails

* Format
  • Loading branch information
josephcsible authored Jan 3, 2025
1 parent 83c7b9b commit 32a527d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,14 @@ impl Context {
let (extensions, supported_extensions) = build_extensions!(context, WebGlRenderingContext);

// Retrieve and parse `GL_VERSION`
let raw_string = context.get_parameter(VERSION).unwrap().as_string().unwrap();
let version = Version::parse(&raw_string).unwrap();
let raw_jsvalue = context
.get_parameter(VERSION)
.expect("context.get_parameter(VERSION) shouldn't throw");
let raw_string = raw_jsvalue
.as_string()
.unwrap_or_else(|| panic!("{:?} should be a string", raw_jsvalue));
let version = Version::parse(&raw_string)
.expect("context.get_parameter(VERSION) should be parseable as an OpenGL version");

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

// Retrieve and parse `GL_VERSION`
let raw_string = context.get_parameter(VERSION).unwrap().as_string().unwrap();
let version = Version::parse(&raw_string).unwrap();
let raw_jsvalue = context
.get_parameter(VERSION)
.expect("context.get_parameter(VERSION) shouldn't throw");
let raw_string = raw_jsvalue
.as_string()
.unwrap_or_else(|| panic!("{:?} should be a string", raw_jsvalue));
let version = Version::parse(&raw_string)
.expect("context.get_parameter(VERSION) should be parseable as an OpenGL version");

Self {
raw: RawRenderingContext::WebGl2(context),
Expand Down

0 comments on commit 32a527d

Please sign in to comment.