Skip to content

Commit

Permalink
Improve panic messages if retrieving/parsing GL_VERSION fails
Browse files Browse the repository at this point in the history
  • Loading branch information
josephcsible authored Dec 26, 2024
1 parent 83c7b9b commit 7ee15b1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ 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 +280,9 @@ 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 7ee15b1

Please sign in to comment.