diff --git a/Cargo.lock b/Cargo.lock index 44938c724..9e6638e98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -123,10 +123,10 @@ dependencies = [ "pin-project 1.0.5", "rand 0.7.3", "regex", - "serde 1.0.123", + "serde 1.0.124", "serde_json", "serde_urlencoded 0.7.0", - "sha-1 0.9.4", + "sha-1", "slab", "time 0.2.25", ] @@ -138,7 +138,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4ca8ce00b267af8ccebbd647de0d61e0674b6e61185cc7a592ff88772bed655" dependencies = [ "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -151,7 +151,7 @@ dependencies = [ "http", "log", "regex", - "serde 1.0.123", + "serde 1.0.124", ] [[package]] @@ -290,7 +290,7 @@ dependencies = [ "mime", "pin-project 1.0.5", "regex", - "serde 1.0.123", + "serde 1.0.124", "serde_json", "serde_urlencoded 0.7.0", "socket2", @@ -323,7 +323,7 @@ checksum = "ad26f77093333e0e7c6ffe54ebe3582d908a104e448723eec6d43d08b07143fb" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -334,7 +334,7 @@ checksum = "b95aceadaf327f18f0df5962fedc1bde2f870566a0b9f65c89508a3b1f79334c" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -481,7 +481,7 @@ checksum = "d7d78656ba01f1b93024b7c3a0467f1608e4be67d725749fdcd7d2c7678fd7a2" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -505,7 +505,7 @@ dependencies = [ "memchr", "num_cpus", "once_cell", - "pin-project-lite 0.2.5", + "pin-project-lite 0.2.6", "pin-utils", "slab", "wasm-bindgen-futures", @@ -539,7 +539,7 @@ checksum = "25f9db3b38af870bf7e5cc649167533b493928e50744e2c30ae350230b414670" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -550,7 +550,7 @@ checksum = "a3548b8efc9f8e8a5a0a2808c5bd8451a9031b9e5b879a79590304ae928b0a70" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -561,13 +561,13 @@ checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" [[package]] name = "async-trait" -version = "0.1.42" +version = "0.1.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3a45e77e34375a7923b1e8febb049bb011f064714a8e17a1a616fef01da13d" +checksum = "36ea56748e10732c49404c153638a15ec3d6211ec5ff35d9bb20e13b93576adf" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -612,7 +612,7 @@ dependencies = [ "mime", "percent-encoding", "rand 0.7.3", - "serde 1.0.123", + "serde 1.0.124", "serde_json", "serde_urlencoded 0.7.0", ] @@ -666,34 +666,13 @@ dependencies = [ "constant_time_eq", ] -[[package]] -name = "block-buffer" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" -dependencies = [ - "block-padding", - "byte-tools", - "byteorder", - "generic-array 0.12.4", -] - [[package]] name = "block-buffer" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "generic-array 0.14.4", -] - -[[package]] -name = "block-padding" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" -dependencies = [ - "byte-tools", + "generic-array", ] [[package]] @@ -745,12 +724,6 @@ version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" -[[package]] -name = "byte-tools" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" - [[package]] name = "byteorder" version = "1.4.2" @@ -840,7 +813,7 @@ dependencies = [ "bytes 1.0.1", "futures-util", "memchr", - "pin-project-lite 0.2.5", + "pin-project-lite 0.2.6", "tokio 0.2.25", ] @@ -862,7 +835,7 @@ dependencies = [ "lazy_static", "nom", "rust-ini", - "serde 1.0.123", + "serde 1.0.124", "serde-hjson", "serde_json", "toml", @@ -1008,7 +981,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8f45d9ad417bcef4817d614a501ab55cdd96a6fdb24f49aab89a54acfd66b19" dependencies = [ "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -1046,7 +1019,7 @@ dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", "regex", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -1056,7 +1029,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed431abf442833fd62ad7cc527a3833d969155c803f0dcf7f8a68db8adddc4c5" dependencies = [ "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -1090,7 +1063,7 @@ dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", "strsim 0.9.3", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -1104,7 +1077,7 @@ dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", "strsim 0.10.0", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -1115,7 +1088,7 @@ checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" dependencies = [ "darling_core 0.10.2", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -1126,7 +1099,7 @@ checksum = "c0220073ce504f12a70efc4e7cdaea9e9b1b324872e7ad96a208056d7a638b81" dependencies = [ "darling_core 0.12.2", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -1139,7 +1112,7 @@ dependencies = [ "config", "crossbeam-queue", "num_cpus", - "serde 1.0.123", + "serde 1.0.124", "tokio 0.2.25", ] @@ -1155,7 +1128,7 @@ dependencies = [ "futures 0.3.13", "log", "redis", - "serde 1.0.123", + "serde 1.0.124", ] [[package]] @@ -1166,7 +1139,7 @@ checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -1179,7 +1152,7 @@ dependencies = [ "derive_builder_core", "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -1191,7 +1164,7 @@ dependencies = [ "darling 0.10.2", "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -1202,7 +1175,7 @@ checksum = "41cb0e6161ad61ed084a36ba71fbba9e3ac5aee3606fb607fe08da6acbcf3d8c" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -1211,22 +1184,13 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" -[[package]] -name = "digest" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" -dependencies = [ - "generic-array 0.12.4", -] - [[package]] name = "digest" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.4", + "generic-array", ] [[package]] @@ -1298,7 +1262,7 @@ dependencies = [ "heck", "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -1325,16 +1289,10 @@ checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", "synstructure", ] -[[package]] -name = "fake-simd" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" - [[package]] name = "fantoccini" version = "0.17.3" @@ -1349,9 +1307,9 @@ dependencies = [ "hyper 0.14.4", "hyper-tls", "mime", - "serde 1.0.123", + "serde 1.0.124", "serde_json", - "tokio 1.2.0", + "tokio 1.3.0", "url", "webdriver", ] @@ -1536,7 +1494,7 @@ dependencies = [ "futures-io", "memchr", "parking", - "pin-project-lite 0.2.5", + "pin-project-lite 0.2.6", "waker-fn", ] @@ -1549,7 +1507,7 @@ dependencies = [ "proc-macro-hack", "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -1584,7 +1542,7 @@ dependencies = [ "futures-sink", "futures-task", "memchr", - "pin-project-lite 0.2.5", + "pin-project-lite 0.2.6", "pin-utils", "proc-macro-hack", "proc-macro-nested", @@ -1606,15 +1564,6 @@ version = "0.3.55" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" -[[package]] -name = "generic-array" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" -dependencies = [ - "typenum", -] - [[package]] name = "generic-array" version = "0.14.4" @@ -1649,16 +1598,16 @@ dependencies = [ [[package]] name = "gherkin_rust" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f70e36c2b9e5ec714060599e3a983dc7a9123f32c5c63ee638c1e024f36d5c1" +checksum = "68ff71b5e012707c7c18bdb710e07736898aba0451f6ffbd435c892dd993053c" dependencies = [ "heck", "peg", "quote 1.0.9", - "serde 1.0.123", + "serde 1.0.124", "serde_json", - "syn 1.0.60", + "syn 1.0.63", "textwrap 0.12.1", "thiserror", "typed-builder", @@ -1672,7 +1621,7 @@ checksum = "1a5bcf1bbeab73aa4cf2fde60a846858dc036163c7c33bec309f8d17de785479" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -1752,8 +1701,8 @@ dependencies = [ "http", "indexmap", "slab", - "tokio 1.2.0", - "tokio-util 0.6.3", + "tokio 1.3.0", + "tokio-util 0.6.4", "tracing", ] @@ -1765,9 +1714,9 @@ checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" [[package]] name = "headers" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62689dc57c7456e69712607ffcbd0aa1dfcccf9af73727e9b25bc1825375cac3" +checksum = "f0b7591fb62902706ae8e7aaff416b1b0fa2c0fd0878b46dc13baa3712d8a855" dependencies = [ "base64 0.13.0", "bitflags", @@ -1775,7 +1724,7 @@ dependencies = [ "headers-core", "http", "mime", - "sha-1 0.8.2", + "sha-1", "time 0.1.43", ] @@ -1873,7 +1822,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac34a56cfd4acddb469cc7fff187ed5ac36f498ba085caf8bbc725e3ff474058" dependencies = [ "humantime", - "serde 1.0.123", + "serde 1.0.124", ] [[package]] @@ -1918,7 +1867,7 @@ dependencies = [ "itoa", "pin-project 1.0.5", "socket2", - "tokio 1.2.0", + "tokio 1.3.0", "tower-service", "tracing", "want", @@ -1933,7 +1882,7 @@ dependencies = [ "bytes 1.0.1", "hyper 0.14.4", "native-tls", - "tokio 1.2.0", + "tokio 1.3.0", "tokio-native-tls", ] @@ -1974,9 +1923,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.6.1" +version = "1.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb1fa934250de4de8aef298d81c729a7d33d8c239daa3a7575e6b92bfc7313b" +checksum = "824845a0bf897a9042383849b02c1bc219c2383772efcd5c6f9766fa4b81aef3" dependencies = [ "autocfg", "hashbrown", @@ -2016,7 +1965,7 @@ checksum = "75c094e94816723ab936484666968f5b58060492e880f3c8d00489a1e244fa51" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -2125,9 +2074,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.87" +version = "0.2.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "265d751d31d6780a3f956bb5b8022feba2d94eeee5a84ba64f4212eedca42213" +checksum = "03b07a082330a35e43f63177cc01689da34fbffa0105e1246cf0311472cac73a" [[package]] name = "linked-hash-map" @@ -2232,7 +2181,7 @@ dependencies = [ "reqwest", "rust-argon2", "rust-crypto", - "serde 1.0.123", + "serde 1.0.124", "serde_json", "serde_yaml", "serial_test", @@ -2246,8 +2195,8 @@ dependencies = [ "subtle", "tempfile", "tokio 0.2.25", - "tokio 1.2.0", - "tokio-util 0.6.3", + "tokio 1.3.0", + "tokio-util 0.6.4", "toml", "tonic", "url", @@ -2262,7 +2211,7 @@ dependencies = [ "async-trait", "derive_more", "medea-macro 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.123", + "serde 1.0.124", "serde_json", "serde_with", ] @@ -2276,7 +2225,7 @@ dependencies = [ "async-trait", "derive_more", "medea-macro 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.123", + "serde 1.0.124", "serde_json", "serde_with", ] @@ -2295,7 +2244,7 @@ dependencies = [ "humantime-serde", "medea-control-api-proto 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf", - "serde 1.0.123", + "serde 1.0.124", "serde_json", "slog", "slog-async", @@ -2381,7 +2330,7 @@ dependencies = [ "medea-reactive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "mockall", "predicates-tree", - "serde 1.0.123", + "serde 1.0.124", "serde_json", "tracerr", "url", @@ -2402,7 +2351,7 @@ dependencies = [ "medea-jason", "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", "synstructure", ] @@ -2415,7 +2364,7 @@ dependencies = [ "Inflector", "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", "synstructure", ] @@ -2563,7 +2512,7 @@ dependencies = [ "cfg-if 1.0.0", "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -2687,12 +2636,6 @@ version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" -[[package]] -name = "opaque-debug" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" - [[package]] name = "opaque-debug" version = "0.3.0" @@ -2838,7 +2781,7 @@ checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -2849,7 +2792,7 @@ checksum = "758669ae3558c6f74bd2a18b41f7ac0b5a195aea6639d6a9b5e5d1ad5ba24c0b" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -2860,9 +2803,9 @@ checksum = "257b64915a082f7811703966789728173279bdebb956b143dbcd23f6f970a777" [[package]] name = "pin-project-lite" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cf491442e4b033ed1c722cb9f0df5fcfcf4de682466c46469c36bc47dc5548a" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" [[package]] name = "pin-utils" @@ -3001,7 +2944,7 @@ dependencies = [ "itertools 0.8.2", "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -3251,9 +3194,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0460542b551950620a3648c6aa23318ac6b3cd779114bd873209e6e8b5eb1c34" +checksum = "bf12057f289428dbf5c591c74bf10392e4a8003f993405a902f20117019022d4" dependencies = [ "base64 0.13.0", "bytes 1.0.1", @@ -3271,11 +3214,11 @@ dependencies = [ "mime", "native-tls", "percent-encoding", - "pin-project-lite 0.2.5", - "serde 1.0.123", + "pin-project-lite 0.2.6", + "serde 1.0.124", "serde_json", "serde_urlencoded 0.7.0", - "tokio 1.2.0", + "tokio 1.3.0", "tokio-native-tls", "url", "wasm-bindgen", @@ -3390,9 +3333,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "security-framework" -version = "2.1.1" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfd318104249865096c8da1dfabf09ddbb6d0330ea176812a62ec75e40c4166" +checksum = "d493c5f39e02dfb062cd8f33301f90f9b13b650e8c1b1d0fd75c19dd64bff69d" dependencies = [ "bitflags", "core-foundation", @@ -3434,9 +3377,9 @@ checksum = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8" [[package]] name = "serde" -version = "1.0.123" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d5161132722baa40d802cc70b15262b98258453e85e5d1d365c757c73869ae" +checksum = "bd761ff957cb2a45fbb9ab3da6512de9de55872866160b23c25f1a841e99d29f" dependencies = [ "serde_derive", ] @@ -3456,13 +3399,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.123" +version = "1.0.124" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" +checksum = "1800f7693e94e186f5e25a28291ae1570da908aff7d97a095dec1e56ff99069b" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -3473,7 +3416,7 @@ checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" dependencies = [ "itoa", "ryu", - "serde 1.0.123", + "serde 1.0.124", ] [[package]] @@ -3493,7 +3436,7 @@ checksum = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" dependencies = [ "dtoa", "itoa", - "serde 1.0.123", + "serde 1.0.124", "url", ] @@ -3506,7 +3449,7 @@ dependencies = [ "form_urlencoded", "itoa", "ryu", - "serde 1.0.123", + "serde 1.0.124", ] [[package]] @@ -3515,7 +3458,7 @@ version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b44be9227e214a0420707c9ca74c2d4991d9955bae9415a8f93f05cebf561be5" dependencies = [ - "serde 1.0.123", + "serde 1.0.124", "serde_with_macros", ] @@ -3528,7 +3471,7 @@ dependencies = [ "darling 0.12.2", "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -3539,7 +3482,7 @@ checksum = "15654ed4ab61726bf918a39cb8d98a2e2995b002387807fa6ba58fdf7f59bb23" dependencies = [ "dtoa", "linked-hash-map 0.5.4", - "serde 1.0.123", + "serde 1.0.124", "yaml-rust", ] @@ -3562,19 +3505,7 @@ checksum = "b2acd6defeddb41eb60bb468f8825d0cfd0c2a76bc03bfd235b6a1dc4f6a1ad5" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", -] - -[[package]] -name = "sha-1" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" -dependencies = [ - "block-buffer 0.7.3", - "digest 0.8.1", - "fake-simd", - "opaque-debug 0.2.3", + "syn 1.0.63", ] [[package]] @@ -3583,11 +3514,11 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfebf75d25bd900fd1e7d11501efab59bc846dbc76196839663e6637bba9f25f" dependencies = [ - "block-buffer 0.9.0", + "block-buffer", "cfg-if 1.0.0", "cpuid-bool", - "digest 0.9.0", - "opaque-debug 0.3.0", + "digest", + "opaque-debug", ] [[package]] @@ -3661,7 +3592,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddc0d2aff1f8f325ef660d9a0eb6e6dcd20b30b3f581a5897f58bf42d061c37a" dependencies = [ "chrono", - "serde 1.0.123", + "serde 1.0.124", "serde_json", "slog", ] @@ -3715,7 +3646,7 @@ checksum = "133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -3766,9 +3697,9 @@ checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "serde 1.0.123", + "serde 1.0.124", "serde_derive", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -3780,11 +3711,11 @@ dependencies = [ "base-x", "proc-macro2 1.0.24", "quote 1.0.9", - "serde 1.0.123", + "serde 1.0.124", "serde_derive", "serde_json", "sha1", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -3830,9 +3761,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.60" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" +checksum = "8fd9bc7ccc2688b3344c2f48b9b546648b25ce0b20fc717ee7fa7981a8ca9717" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", @@ -3847,7 +3778,7 @@ checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", "unicode-xid 0.2.1", ] @@ -3937,7 +3868,7 @@ checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -4003,7 +3934,7 @@ dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", "standback", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -4046,9 +3977,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8190d04c665ea9e6b6a0dc45523ade572c088d2e6566244c1122671dbf4ae3a" +checksum = "8d56477f6ed99e10225f38f9f75f872f29b8b8bd8c0b946f63345bb144e9eeda" dependencies = [ "autocfg", "bytes 1.0.1", @@ -4056,7 +3987,7 @@ dependencies = [ "memchr", "mio 0.7.9", "num_cpus", - "pin-project-lite 0.2.5", + "pin-project-lite 0.2.6", "tokio-macros 1.1.0", ] @@ -4068,7 +3999,7 @@ checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -4079,7 +4010,7 @@ checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -4089,7 +4020,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" dependencies = [ "native-tls", - "tokio 1.2.0", + "tokio 1.3.0", ] [[package]] @@ -4109,16 +4040,16 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebb7cb2f00c5ae8df755b252306272cd1790d39728363936e01827e11f0b017b" +checksum = "ec31e5cc6b46e653cf57762f36f71d5e6386391d88a72fd6db4508f8f676fb29" dependencies = [ "bytes 1.0.1", "futures-core", "futures-sink", "log", - "pin-project-lite 0.2.5", - "tokio 1.2.0", + "pin-project-lite 0.2.6", + "tokio 1.3.0", ] [[package]] @@ -4127,7 +4058,7 @@ version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" dependencies = [ - "serde 1.0.123", + "serde 1.0.124", ] [[package]] @@ -4169,7 +4100,7 @@ dependencies = [ "proc-macro2 1.0.24", "prost-build", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -4367,7 +4298,7 @@ checksum = "01ebdc2bb4498ab1ab5f5b73c5803825e60199229ccba0698170e3be0e7f959f" dependencies = [ "cfg-if 1.0.0", "log", - "pin-project-lite 0.2.5", + "pin-project-lite 0.2.6", "tracing-attributes", "tracing-core", ] @@ -4380,7 +4311,7 @@ checksum = "a8a9bd1db7706f2373a190b0d067146caa39350c486f3d455b0e33b431f94c07" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -4410,12 +4341,12 @@ checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41" [[package]] name = "trust-dns-proto" -version = "0.19.6" +version = "0.19.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53861fcb288a166aae4c508ae558ed18b53838db728d4d310aad08270a7d4c2b" +checksum = "1cad71a0c0d68ab9941d2fb6e82f8fb2e86d9945b94e1661dd0aaea2b88215a9" dependencies = [ "async-trait", - "backtrace", + "cfg-if 1.0.0", "enum-as-inner", "futures 0.3.13", "idna", @@ -4430,11 +4361,10 @@ dependencies = [ [[package]] name = "trust-dns-resolver" -version = "0.19.6" +version = "0.19.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6759e8efc40465547b0dfce9500d733c65f969a4cbbfbe3ccf68daaa46ef179e" +checksum = "710f593b371175db53a26d0b38ed2978fafb9e9e8d3868b1acd753ea18df0ceb" dependencies = [ - "backtrace", "cfg-if 0.1.10", "futures 0.3.13", "ipconfig", @@ -4462,7 +4392,7 @@ checksum = "f85f4270f4f449a3f2c0cf2aecc8415e388a597aeacc7d55fc749c5c968c8533" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", ] [[package]] @@ -4625,7 +4555,7 @@ dependencies = [ "mime_guess", "pin-project 0.4.27", "scoped-tls", - "serde 1.0.123", + "serde 1.0.124", "serde_json", "serde_urlencoded 0.6.1", "tokio 0.2.25", @@ -4654,7 +4584,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ee1280240b7c461d6a0071313e08f34a60b0365f14260362e5a2b17d1d31aa7" dependencies = [ "cfg-if 1.0.0", - "serde 1.0.123", + "serde 1.0.124", "serde_json", "wasm-bindgen-macro", ] @@ -4670,7 +4600,7 @@ dependencies = [ "log", "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", "wasm-bindgen-shared", ] @@ -4704,7 +4634,7 @@ checksum = "cc053ec74d454df287b9374ee8abb36ffd5acb95ba87da3ba5b7d3fe20eb401e" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", - "syn 1.0.60", + "syn 1.0.63", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -4771,7 +4701,7 @@ dependencies = [ "cookie 0.12.0", "http", "log", - "serde 1.0.123", + "serde 1.0.124", "serde_derive", "serde_json", "time 0.1.43", diff --git a/Makefile b/Makefile index 002a7e1b8..b4ab8b68f 100644 --- a/Makefile +++ b/Makefile @@ -159,6 +159,7 @@ down.medea: docker.down.medea up.control: cargo build -p medea-control-api-mock + make wait.port port=6565 cargo run -p medea-control-api-mock $(if $(call eq,$(background),yes),&,) diff --git a/jason/src/api/wasm/constraints_update_exception.rs b/jason/src/api/wasm/constraints_update_exception.rs index 74e78deae..2881073d4 100644 --- a/jason/src/api/wasm/constraints_update_exception.rs +++ b/jason/src/api/wasm/constraints_update_exception.rs @@ -7,7 +7,9 @@ use std::iter::FromIterator as _; use derive_more::From; use wasm_bindgen::prelude::*; -use crate::{api::JasonError, room}; +use crate::room; + +use super::JasonError; /// Exception returned from [`RoomHandle::set_local_media_settings()`][1]. /// diff --git a/jason/src/api/wasm/jason_error.rs b/jason/src/api/wasm/jason_error.rs index f79f4fb1f..2bbb0e2ae 100644 --- a/jason/src/api/wasm/jason_error.rs +++ b/jason/src/api/wasm/jason_error.rs @@ -1,36 +1,81 @@ //! App error exported to JS side. -use derive_more::From; +use std::fmt::{Debug, Display}; + +use derive_more::{Display, From}; +use tracerr::{Trace, Traced}; use wasm_bindgen::prelude::*; -use crate::utils; +use crate::{platform, utils::JsCaused}; /// Representation of an app error exported to JS side. /// /// Contains JS side error if it's the cause, and a trace information. #[wasm_bindgen] -#[derive(From)] -pub struct JasonError(utils::JasonError); +#[derive(From, Clone, Debug, Display)] +#[display(fmt = "{}: {}\n{}", name, message, trace)] +pub struct JasonError { + /// Name of this [`JasonError`]. + name: &'static str, + + /// Message describing this [`JasonError`]. + message: String, + + /// [`Trace`] information of this [`JasonError`]. + trace: Trace, + + /// Optional cause of this [`JasonError`] as a JS side error. + source: Option, +} #[wasm_bindgen] impl JasonError { /// Returns a name of this error. + #[must_use] pub fn name(&self) -> String { - self.0.name() + self.name.to_owned() } - /// Returns a message of this errors. + /// Returns a message of this error. + #[must_use] pub fn message(&self) -> String { - self.0.message() + self.message.clone() } /// Returns a trace information of this error. + #[must_use] pub fn trace(&self) -> String { - self.0.trace() + self.trace.to_string() } /// Returns a JS side error if it's the cause. + #[must_use] pub fn source(&self) -> Option { - self.0.source().and_then(|a| a.sys_cause) + self.source.clone().and_then(|e| e.sys_cause) + } +} + +impl From<(E, Trace)> for JasonError +where + E::Error: Into, +{ + #[inline] + fn from((err, trace): (E, Trace)) -> Self { + Self { + name: err.name(), + message: err.to_string(), + trace, + source: err.js_cause().map(Into::into), + } + } +} + +impl From> for JasonError +where + E::Error: Into, +{ + #[inline] + fn from(traced: Traced) -> Self { + Self::from(traced.into_parts()) } } diff --git a/jason/src/api/wasm/media_manager_handle.rs b/jason/src/api/wasm/media_manager_handle.rs index 2314ef24d..9700c7df0 100644 --- a/jason/src/api/wasm/media_manager_handle.rs +++ b/jason/src/api/wasm/media_manager_handle.rs @@ -8,10 +8,12 @@ use wasm_bindgen::prelude::*; use wasm_bindgen_futures::future_to_promise; use crate::{ - api::{InputDeviceInfo, JasonError, LocalMediaTrack, MediaStreamSettings}, + api::{InputDeviceInfo, LocalMediaTrack, MediaStreamSettings}, media, }; +use super::JasonError; + /// [`MediaManagerHandle`] is a weak reference to a [`MediaManager`]. /// /// [`MediaManager`] performs all the media acquisition requests diff --git a/jason/src/api/wasm/media_stream_settings.rs b/jason/src/api/wasm/media_stream_settings.rs index cbfddda0c..99ff4927c 100644 --- a/jason/src/api/wasm/media_stream_settings.rs +++ b/jason/src/api/wasm/media_stream_settings.rs @@ -71,6 +71,8 @@ impl AudioTrackConstraints { #[derive(From, Into)] pub struct DeviceVideoTrackConstraints(media::DeviceVideoTrackConstraints); +/// Constraints applicable to video tracks that are sourced from a screen +/// capturing. #[wasm_bindgen] impl DeviceVideoTrackConstraints { /// Creates new [`DeviceVideoTrackConstraints`] with none constraints diff --git a/jason/src/api/wasm/mod.rs b/jason/src/api/wasm/mod.rs index 6481556de..72d7e5e5c 100644 --- a/jason/src/api/wasm/mod.rs +++ b/jason/src/api/wasm/mod.rs @@ -3,9 +3,6 @@ //! //! [`Jason`]: crate::api::Jason -use derive_more::Display; -use wasm_bindgen::prelude::*; - pub mod connection_handle; pub mod constraints_update_exception; pub mod input_device_info; @@ -19,6 +16,11 @@ pub mod remote_media_track; pub mod room_close_reason; pub mod room_handle; +use derive_more::Display; +use wasm_bindgen::prelude::*; + +pub use self::jason_error::JasonError; + /// [MediaStreamTrack.kind][1] representation. /// /// [1]: https://w3.org/TR/mediacapture-streams/#dom-mediastreamtrack-kind diff --git a/jason/src/api/wasm/reconnect_handle.rs b/jason/src/api/wasm/reconnect_handle.rs index b748f0882..948f3ad07 100644 --- a/jason/src/api/wasm/reconnect_handle.rs +++ b/jason/src/api/wasm/reconnect_handle.rs @@ -5,7 +5,9 @@ use js_sys::Promise; use wasm_bindgen::prelude::*; use wasm_bindgen_futures::future_to_promise; -use crate::{api::JasonError, rpc}; +use crate::rpc; + +use super::JasonError; /// Handle that JS side can reconnect to a media server with when a connection /// is lost. diff --git a/jason/src/api/wasm/room_handle.rs b/jason/src/api/wasm/room_handle.rs index 2d0b3f593..76cd2069d 100644 --- a/jason/src/api/wasm/room_handle.rs +++ b/jason/src/api/wasm/room_handle.rs @@ -8,13 +8,12 @@ use wasm_bindgen::{prelude::*, JsValue}; use wasm_bindgen_futures::future_to_promise; use crate::{ - api::{ - ConstraintsUpdateException, JasonError, MediaSourceKind, - MediaStreamSettings, - }, + api::{ConstraintsUpdateException, MediaSourceKind, MediaStreamSettings}, room, }; +use super::JasonError; + /// JS side handle to a [`Room`] where all the media happens. /// /// Like all handles it contains a weak reference to the object that is managed @@ -171,6 +170,12 @@ impl RoomHandle { /// Mutes outbound audio in this [`Room`]. /// + /// # Errors + /// + /// With `name = 'MediaConnections'` if [`RoomHandle::unmute_audio()`] was + /// called while muting or a media server didn't approve this state + /// transition. + /// /// [`Room`]: room::Room pub fn mute_audio(&self) -> Promise { let this = self.0.clone(); @@ -183,6 +188,12 @@ impl RoomHandle { /// Unmutes outbound audio in this [`Room`]. /// + /// # Errors + /// + /// With `name = 'MediaConnections'` if [`RoomHandle::mute_audio()`] was + /// called while unmuting or a media server didn't approve this state + /// transition. + /// /// [`Room`]: room::Room pub fn unmute_audio(&self) -> Promise { let this = self.0.clone(); @@ -195,6 +206,12 @@ impl RoomHandle { /// Mutes outbound video in this [`Room`]. /// + /// # Errors + /// + /// With `name = 'MediaConnections'` if [`RoomHandle::unmute_video()`] was + /// called while muting or a media server didn't approve this state + /// transition. + /// /// [`Room`]: room::Room pub fn mute_video(&self, source_kind: Option) -> Promise { let this = self.0.clone(); @@ -209,6 +226,12 @@ impl RoomHandle { /// Unmutes outbound video in this [`Room`]. /// + /// # Errors + /// + /// With `name = 'MediaConnections'` if [`RoomHandle::mute_video()`] was + /// called while unmuting or a media server didn't approve this state + /// transition. + /// /// [`Room`]: room::Room pub fn unmute_video( &self, @@ -226,6 +249,13 @@ impl RoomHandle { /// Disables outbound audio in this [`Room`]. /// + /// # Errors + /// + /// With `name = 'MediaConnections'` if the target sender is configured as + /// `required` by a media server or [`RoomHandle::enable_audio()`] was + /// called while disabling or a media server didn't approve this state + /// transition. + /// /// [`Room`]: room::Room pub fn disable_audio(&self) -> Promise { let this = self.0.clone(); @@ -238,6 +268,15 @@ impl RoomHandle { /// Enables outbound audio in this [`Room`]. /// + /// # Errors + /// + /// With `name = 'MediaConnections'` if [`RoomHandle::disable_audio()`] was + /// called while enabling or a media server didn't approve this state + /// transition. + /// + /// With `name = 'MediaManagerError'` if media acquisition request to User + /// Agent failed. + /// /// [`Room`]: room::Room pub fn enable_audio(&self) -> Promise { let this = self.0.clone(); @@ -251,6 +290,13 @@ impl RoomHandle { /// Disables outbound video. /// /// Affects only video with a specific [`MediaSourceKind`] if specified. + /// + /// # Errors + /// + /// With `name = 'MediaConnections'` if the target sender is configured as + /// `required` by a media server or [`RoomHandle::enable_video()`] was + /// called while disabling or a media server didn't approve this state + /// transition. pub fn disable_video( &self, source_kind: Option, @@ -269,6 +315,15 @@ impl RoomHandle { /// Enables outbound video. /// /// Affects only video with a specific [`MediaSourceKind`] if specified. + /// + /// # Errors + /// + /// With `name = 'MediaConnections'` if [`RoomHandle::disable_video()`] was + /// called while enabling or a media server didn't approve this state + /// transition. + /// + /// With `name = 'MediaManagerError'` if media acquisition request to User + /// Agent failed. pub fn enable_video( &self, source_kind: Option, @@ -285,6 +340,12 @@ impl RoomHandle { /// Disables inbound audio in this [`Room`]. /// + /// # Errors + /// + /// With `name = 'MediaConnections'` if + /// [`RoomHandle::enable_remote_audio()`] was called while disabling or a + /// media server didn't approve this state transition. + /// /// [`Room`]: room::Room pub fn disable_remote_audio(&self) -> Promise { let this = self.0.clone(); @@ -299,6 +360,12 @@ impl RoomHandle { /// Disables inbound video in this [`Room`]. /// + /// # Errors + /// + /// With `name = 'MediaConnections'` if + /// [`RoomHandle::enable_remote_video()`] was called while disabling or + /// a media server didn't approve this state transition. + /// /// [`Room`]: room::Room pub fn disable_remote_video(&self) -> Promise { let this = self.0.clone(); @@ -313,6 +380,12 @@ impl RoomHandle { /// Enables inbound audio in this [`Room`]. /// + /// # Errors + /// + /// With `name = 'MediaConnections'` if + /// [`RoomHandle::disable_remote_audio()`] was called while enabling or a + /// media server didn't approve this state transition. + /// /// [`Room`]: room::Room pub fn enable_remote_audio(&self) -> Promise { let this = self.0.clone(); @@ -325,6 +398,12 @@ impl RoomHandle { /// Enables inbound video in this [`Room`]. /// + /// # Errors + /// + /// With `name = 'MediaConnections'` if + /// [`RoomHandle::disable_remote_video()`] was called while enabling or a + /// media server didn't approve this state transition. + /// /// [`Room`]: room::Room pub fn enable_remote_video(&self) -> Promise { let this = self.0.clone(); diff --git a/jason/src/connection.rs b/jason/src/connection.rs index f6c24814b..6cff08a88 100644 --- a/jason/src/connection.rs +++ b/jason/src/connection.rs @@ -1,22 +1,16 @@ //! [`Connection`] with a specific remote `Member`. -// TODO: Remove when moving `JasonError` to `api::wasm`. -#![allow(clippy::missing_errors_doc)] - use std::{ cell::{Cell, RefCell}, collections::{HashMap, HashSet}, rc::{Rc, Weak}, }; +use derive_more::Display; use medea_client_api_proto::{ConnectionQualityScore, MemberId, PeerId}; +use tracerr::Traced; -use crate::{ - api, - media::track::remote, - platform, - utils::{HandlerDetachedError, JasonError}, -}; +use crate::{api, media::track::remote, platform, utils::JsCaused}; /// Service which manages [`Connection`]s with remote `Member`s. #[derive(Default)] @@ -90,6 +84,15 @@ impl Connections { } } +/// Errors that may occur in a [`ConnectionHandle`]. +#[derive(Clone, Copy, Debug, Display, JsCaused)] +#[js(error = "platform::Error")] +pub enum ConnectionError { + /// [`ConnectionHandle`]'s [`Weak`] pointer is detached. + #[display(fmt = "Connection is in detached state")] + Detached, +} + /// External handler to a [`Connection`] with a remote `Member`. /// /// Actually, represents a [`Weak`]-based handle to `InnerConnection`. @@ -117,35 +120,63 @@ struct InnerConnection { impl ConnectionHandle { /// Sets callback, invoked when this `Connection` will close. + /// + /// # Errors + /// + /// With [`ConnectionError::Detached`] if [`Weak`] pointer upgrade fails. pub fn on_close( &self, f: platform::Function<()>, - ) -> Result<(), JasonError> { - upgrade_or_detached!(self.0).map(|inner| inner.on_close.set_func(f)) + ) -> Result<(), Traced> { + self.0 + .upgrade() + .ok_or_else(|| tracerr::new!(ConnectionError::Detached)) + .map(|inner| inner.on_close.set_func(f)) } /// Returns remote `Member` ID. - pub fn get_remote_member_id(&self) -> Result { - upgrade_or_detached!(self.0).map(|inner| inner.remote_id.0.clone()) + /// + /// # Errors + /// + /// With [`ConnectionError::Detached`] if [`Weak`] pointer upgrade fails. + pub fn get_remote_member_id( + &self, + ) -> Result> { + self.0 + .upgrade() + .ok_or_else(|| tracerr::new!(ConnectionError::Detached)) + .map(|inner| inner.remote_id.0.clone()) } /// Sets callback, invoked when a new [`remote::Track`] will is added to /// this [`Connection`]. + /// + /// # Errors + /// + /// With [`ConnectionError::Detached`] if [`Weak`] pointer upgrade fails. pub fn on_remote_track_added( &self, f: platform::Function, - ) -> Result<(), JasonError> { - upgrade_or_detached!(self.0) + ) -> Result<(), Traced> { + self.0 + .upgrade() + .ok_or_else(|| tracerr::new!(ConnectionError::Detached)) .map(|inner| inner.on_remote_track_added.set_func(f)) } /// Sets callback, invoked when a connection quality score is updated by /// a server. + /// + /// # Errors + /// + /// With [`ConnectionError::Detached`] if [`Weak`] pointer upgrade fails. pub fn on_quality_score_update( &self, f: platform::Function, - ) -> Result<(), JasonError> { - upgrade_or_detached!(self.0) + ) -> Result<(), Traced> { + self.0 + .upgrade() + .ok_or_else(|| tracerr::new!(ConnectionError::Detached)) .map(|inner| inner.on_quality_score_update.set_func(f)) } } diff --git a/jason/src/media/manager.rs b/jason/src/media/manager.rs index 2b484561c..d57bb7284 100644 --- a/jason/src/media/manager.rs +++ b/jason/src/media/manager.rs @@ -1,8 +1,5 @@ //! Acquiring and storing [`local::Track`]s. -// TODO: Remove when moving `JasonError` to `api::wasm`. -#![allow(clippy::missing_errors_doc)] - use std::{ cell::RefCell, collections::HashMap, @@ -19,7 +16,7 @@ use crate::{ MultiSourceTracksConstraints, }, platform, - utils::{HandlerDetachedError, JasonError, JsCaused}, + utils::JsCaused, }; use super::track::local; @@ -60,6 +57,10 @@ pub enum MediaManagerError { /// [3]: https://w3.org/TR/screen-capture#dom-mediadevices-getdisplaymedia #[display(fmt = "{} track is ended", _0)] LocalTrackIsEnded(MediaKind), + + /// [`MediaManagerHandle`]'s inner [`Weak`] pointer could not be upgraded. + #[display(fmt = "MediaManagerHandle is in detached state")] + Detached, } type Result = std::result::Result>; @@ -322,23 +323,47 @@ impl MediaManagerHandle { /// Returns a list of [`platform::InputDeviceInfo`] objects representing /// available media input and output devices, such as microphones, cameras, /// and so forth. + /// + /// # Errors + /// + /// With [`MediaManagerError::CouldNotGetMediaDevices`] or + /// [`MediaManagerError::EnumerateDevicesFailed`] if devices enumeration + /// failed. pub async fn enumerate_devices( &self, - ) -> std::result::Result, JasonError> { + ) -> Result> { InnerMediaManager::enumerate_devices() .await .map_err(tracerr::wrap!(=> MediaManagerError)) - .map_err(JasonError::from) } /// Returns [`local::LocalMediaTrack`]s objects, built from the provided /// [`MediaStreamSettings`]. + /// + /// # Errors + /// + /// With [`MediaManagerError::Detached`] if [`Weak`] pointer upgrade fails. + /// + /// With [`MediaManagerError::CouldNotGetMediaDevices`] if media devices + /// request to User Agent failed. + /// + /// With [`MediaManagerError::GetUserMediaFailed`] if [getUserMedia()][1] + /// request failed. + /// + /// With [`MediaManagerError::GetDisplayMediaFailed`] if + /// [getDisplayMedia()][2] request failed. + /// + /// [1]: https://tinyurl.com/w3-streams#dom-mediadevices-getusermedia + /// [2]: https://w3.org/TR/screen-capture/#dom-mediadevices-getdisplaymedia pub async fn init_local_tracks( &self, caps: MediaStreamSettings, - ) -> std::result::Result, JasonError> { - upgrade_or_detached!(self.0, JasonError)? - .get_tracks(caps) + ) -> Result> { + let this = self + .0 + .upgrade() + .ok_or_else(|| tracerr::new!(MediaManagerError::Detached))?; + this.get_tracks(caps) .await .map(|tracks| { tracks @@ -347,6 +372,5 @@ impl MediaManagerHandle { .collect::>() }) .map_err(tracerr::wrap!(=> MediaManagerError)) - .map_err(JasonError::from) } } diff --git a/jason/src/peer/mod.rs b/jason/src/peer/mod.rs index e5a5941cd..6a5e98b39 100644 --- a/jason/src/peer/mod.rs +++ b/jason/src/peer/mod.rs @@ -26,6 +26,7 @@ use medea_macro::dispatchable; use tracerr::Traced; use crate::{ + api::JasonError, connection::Connections, media::{ track::{local, remote}, @@ -33,7 +34,7 @@ use crate::{ MediaStreamSettings, RecvConstraints, }, platform, - utils::{JasonError, JsCaused}, + utils::JsCaused, }; #[doc(inline)] @@ -69,7 +70,7 @@ pub enum PeerError { /// /// [1]: https://w3.org/TR/webrtc/#dom-rtcpeerconnection #[display(fmt = "{}", _0)] - RtcPeerConnection(#[js(cause)] platform::RTCPeerConnectionError), + RtcPeerConnection(#[js(cause)] platform::RtcPeerConnectionError), /// Errors that may occur when validating [`TracksRequest`] or parsing /// [`local::Track`]s. @@ -385,10 +386,11 @@ impl PeerConnection { // Bind to `track` event. let media_connections = Rc::clone(&peer.media_connections); peer.peer.on_track(Some(move |track, transceiver| { - if let Err(err) = - media_connections.add_remote_track(track, transceiver) + if let Err(e) = media_connections + .add_remote_track(track, transceiver) + .map_err(tracerr::map_from_and_wrap!(=> PeerError)) { - JasonError::from(err).print(); + log::error!("{}", e); }; })); @@ -499,11 +501,14 @@ impl PeerConnection { /// Sends [`platform::RtcStats`] update of this [`PeerConnection`] to a /// server. pub async fn scrape_and_send_peer_stats(&self) { - match self.peer.get_stats().await { + match self + .peer + .get_stats() + .await + .map_err(tracerr::map_from_and_wrap!(=> PeerError)) + { Ok(stats) => self.send_peer_stats(stats), - Err(e) => { - JasonError::from(e).print(); - } + Err(e) => log::error!("{}", e), }; } @@ -825,12 +830,12 @@ impl PeerConnection { /// /// # Errors /// - /// With [`RTCPeerConnectionError::SetRemoteDescriptionFailed`][3] if + /// With [`RtcPeerConnectionError::SetRemoteDescriptionFailed`][3] if /// [RTCPeerConnection.setRemoteDescription()][2] fails. /// /// [1]: https://w3.org/TR/webrtc/#rtcpeerconnection-interface /// [2]: https://w3.org/TR/webrtc/#dom-peerconnection-setremotedescription - /// [3]: platform::RTCPeerConnectionError::SetRemoteDescriptionFailed + /// [3]: platform::RtcPeerConnectionError::SetRemoteDescriptionFailed async fn set_remote_answer(&self, answer: String) -> Result<()> { self.set_remote_description(platform::SdpType::Answer(answer)) .await @@ -841,7 +846,7 @@ impl PeerConnection { /// /// # Errors /// - /// With [`platform::RTCPeerConnectionError::SetRemoteDescriptionFailed`] if + /// With [`platform::RtcPeerConnectionError::SetRemoteDescriptionFailed`] if /// [RTCPeerConnection.setRemoteDescription()][2] fails. /// /// [1]: https://w3.org/TR/webrtc/#rtcpeerconnection-interface @@ -857,10 +862,10 @@ impl PeerConnection { /// /// # Errors /// - /// With [`platform::RTCPeerConnectionError::SetRemoteDescriptionFailed`] if + /// With [`platform::RtcPeerConnectionError::SetRemoteDescriptionFailed`] if /// [RTCPeerConnection.setRemoteDescription()][2] fails. /// - /// With [`platform::RTCPeerConnectionError::AddIceCandidateFailed`] if + /// With [`platform::RtcPeerConnectionError::AddIceCandidateFailed`] if /// [RtcPeerConnection.addIceCandidate()][3] fails when adding buffered ICE /// candidates. /// @@ -904,12 +909,12 @@ impl PeerConnection { /// /// # Errors /// - /// With [`RTCPeerConnectionError::AddIceCandidateFailed`][2] if + /// With [`RtcPeerConnectionError::AddIceCandidateFailed`][2] if /// [RtcPeerConnection.addIceCandidate()][3] fails to add buffered /// [ICE candidates][1]. /// /// [1]: https://tools.ietf.org/html/rfc5245#section-2 - /// [2]: platform::RTCPeerConnectionError::AddIceCandidateFailed + /// [2]: platform::RtcPeerConnectionError::AddIceCandidateFailed /// [3]: https://w3.org/TR/webrtc/#dom-peerconnection-addicecandidate pub async fn add_ice_candidate( &self, diff --git a/jason/src/platform/mod.rs b/jason/src/platform/mod.rs index 8e9eae9b9..3bddbe95e 100644 --- a/jason/src/platform/mod.rs +++ b/jason/src/platform/mod.rs @@ -6,7 +6,7 @@ pub mod transport; pub mod wasm; pub use self::{ - peer_connection::{IceCandidate, RTCPeerConnectionError, SdpType}, + peer_connection::{IceCandidate, RtcPeerConnectionError, SdpType}, rtc_stats::RtcStatsError, transport::{ RpcTransport, TransportError, TransportState, WebSocketRpcTransport, diff --git a/jason/src/platform/peer_connection.rs b/jason/src/platform/peer_connection.rs index 46ca510e2..1a1fe90ee 100644 --- a/jason/src/platform/peer_connection.rs +++ b/jason/src/platform/peer_connection.rs @@ -51,7 +51,7 @@ pub struct IceCandidate { /// [1]: https://w3.org/TR/webrtc/#dom-rtcpeerconnection #[derive(Clone, Debug, Display, From, JsCaused)] #[js(error = "platform::Error")] -pub enum RTCPeerConnectionError { +pub enum RtcPeerConnectionError { /// Occurs when cannot adds new remote candidate to the /// [RTCPeerConnection][1]'s remote description. /// diff --git a/jason/src/platform/wasm/peer_connection.rs b/jason/src/platform/wasm/peer_connection.rs index 8071770e4..cfcb48d3e 100644 --- a/jason/src/platform/wasm/peer_connection.rs +++ b/jason/src/platform/wasm/peer_connection.rs @@ -25,7 +25,7 @@ use crate::{ media::{MediaKind, TrackConstraints}, platform::{ self, get_property_by_name, wasm::utils::EventListener, IceCandidate, - MediaStreamTrack, RTCPeerConnectionError, RtcStats, SdpType, + MediaStreamTrack, RtcPeerConnectionError, RtcStats, SdpType, Transceiver, TransceiverDirection, }, }; @@ -41,7 +41,7 @@ impl From<&TrackConstraints> for MediaKind { } } -type Result = std::result::Result>; +type Result = std::result::Result>; /// Representation of [RTCPeerConnection][1]. /// @@ -108,7 +108,7 @@ impl RtcPeerConnection { /// /// # Errors /// - /// Errors with [`RTCPeerConnectionError::PeerCreationError`] if + /// Errors with [`RtcPeerConnectionError::PeerCreationError`] if /// [`SysRtcPeerConnection`] creation fails. pub fn new(ice_servers: I, is_force_relayed: bool) -> Result where @@ -125,7 +125,7 @@ impl RtcPeerConnection { peer_conf.ice_servers(&RtcIceServers::from(ice_servers)); let peer = SysRtcPeerConnection::new_with_configuration(&peer_conf) .map_err(Into::into) - .map_err(RTCPeerConnectionError::PeerCreationError) + .map_err(RtcPeerConnectionError::PeerCreationError) .map_err(tracerr::wrap!())?; Ok(Self { @@ -142,17 +142,17 @@ impl RtcPeerConnection { /// /// # Errors /// - /// Errors with [`RTCPeerConnectionError::RtcStatsError`] if getting or + /// Errors with [`RtcPeerConnectionError::RtcStatsError`] if getting or /// parsing of [`RtcStats`] fails. /// - /// Errors with [`RTCPeerConnectionError::GetStatsException`] when + /// Errors with [`RtcPeerConnectionError::GetStatsException`] when /// [PeerConnection.getStats][1] promise throws exception. /// /// [1]: https://tinyurl.com/w6hmt5f pub async fn get_stats(&self) -> Result { let js_stats = JsFuture::from(self.peer.get_stats()).await.map_err(|e| { - tracerr::new!(RTCPeerConnectionError::GetStatsException( + tracerr::new!(RtcPeerConnectionError::GetStatsException( platform::Error::from(e) )) })?; @@ -341,7 +341,7 @@ impl RtcPeerConnection { /// /// # Errors /// - /// With [`RTCPeerConnectionError::AddIceCandidateFailed`] if + /// With [`RtcPeerConnectionError::AddIceCandidateFailed`] if /// [RtcPeerConnection.addIceCandidate()][3] fails. /// /// [1]: https://w3.org/TR/webrtc/#rtcpeerconnection-interface @@ -364,7 +364,7 @@ impl RtcPeerConnection { ) .await .map_err(Into::into) - .map_err(RTCPeerConnectionError::AddIceCandidateFailed) + .map_err(RtcPeerConnectionError::AddIceCandidateFailed) .map_err(tracerr::wrap!())?; Ok(()) } @@ -383,7 +383,7 @@ impl RtcPeerConnection { /// /// # Errors /// - /// With [`RTCPeerConnectionError::SetLocalDescriptionFailed`] if + /// With [`RtcPeerConnectionError::SetLocalDescriptionFailed`] if /// [RtcPeerConnection.setLocalDescription()][1] fails. /// /// [1]: https://w3.org/TR/webrtc/#dom-peerconnection-setlocaldescription @@ -400,7 +400,7 @@ impl RtcPeerConnection { JsFuture::from(peer.set_local_description(&desc)) .await .map_err(Into::into) - .map_err(RTCPeerConnectionError::SetLocalDescriptionFailed) + .map_err(RtcPeerConnectionError::SetLocalDescriptionFailed) .map_err(tracerr::wrap!())?; Ok(()) @@ -410,7 +410,7 @@ impl RtcPeerConnection { /// /// # Errors /// - /// With [`RTCPeerConnectionError::SetLocalDescriptionFailed`] if + /// With [`RtcPeerConnectionError::SetLocalDescriptionFailed`] if /// [RtcPeerConnection.setLocalDescription()][1] fails. /// /// [1]: https://w3.org/TR/webrtc/#dom-peerconnection-setlocaldescription @@ -424,7 +424,7 @@ impl RtcPeerConnection { /// /// # Errors /// - /// With [`RTCPeerConnectionError::SetLocalDescriptionFailed`] if + /// With [`RtcPeerConnectionError::SetLocalDescriptionFailed`] if /// [RtcPeerConnection.setLocalDescription()][1] fails. /// /// [1]: https://w3.org/TR/webrtc/#dom-peerconnection-setlocaldescription @@ -441,7 +441,7 @@ impl RtcPeerConnection { /// /// # Errors /// - /// With [`RTCPeerConnectionError::CreateAnswerFailed`] if + /// With [`RtcPeerConnectionError::CreateAnswerFailed`] if /// [RtcPeerConnection.createAnswer()][1] fails. /// /// [1]: https://w3.org/TR/webrtc/#dom-rtcpeerconnection-createanswer @@ -449,7 +449,7 @@ impl RtcPeerConnection { let answer = JsFuture::from(self.peer.create_answer()) .await .map_err(Into::into) - .map_err(RTCPeerConnectionError::CreateAnswerFailed) + .map_err(RtcPeerConnectionError::CreateAnswerFailed) .map_err(tracerr::wrap!())?; let answer = RtcSessionDescription::from(answer).sdp(); @@ -461,7 +461,7 @@ impl RtcPeerConnection { /// /// # Errors /// - /// With [`RTCPeerConnectionError::SetLocalDescriptionFailed`] if + /// With [`RtcPeerConnectionError::SetLocalDescriptionFailed`] if /// [RtcPeerConnection.setLocalDescription()][1] fails. /// /// [1]: https://w3.org/TR/webrtc/#dom-peerconnection-setlocaldescription @@ -473,7 +473,7 @@ impl RtcPeerConnection { )) .await .map_err(Into::into) - .map_err(RTCPeerConnectionError::SetLocalDescriptionFailed) + .map_err(RtcPeerConnectionError::SetLocalDescriptionFailed) .map_err(tracerr::wrap!())?; Ok(()) @@ -487,7 +487,7 @@ impl RtcPeerConnection { /// /// # Errors /// - /// With [`RTCPeerConnectionError::CreateOfferFailed`] if + /// With [`RtcPeerConnectionError::CreateOfferFailed`] if /// [RtcPeerConnection.createOffer()][1] fails. /// /// [1]: https://w3.org/TR/webrtc/#dom-rtcpeerconnection-createoffer @@ -503,7 +503,7 @@ impl RtcPeerConnection { ) .await .map_err(Into::into) - .map_err(RTCPeerConnectionError::CreateOfferFailed) + .map_err(RtcPeerConnectionError::CreateOfferFailed) .map_err(tracerr::wrap!())?; let offer = RtcSessionDescription::from(create_offer).sdp(); @@ -518,7 +518,7 @@ impl RtcPeerConnection { /// /// # Errors /// - /// With [`RTCPeerConnectionError::SetRemoteDescriptionFailed`] if + /// With [`RtcPeerConnectionError::SetRemoteDescriptionFailed`] if /// [RTCPeerConnection.setRemoteDescription()][1] fails. /// /// [1]: https://w3.org/TR/webrtc/#dom-peerconnection-setremotedescription @@ -541,7 +541,7 @@ impl RtcPeerConnection { JsFuture::from(self.peer.set_remote_description(&description)) .await .map_err(Into::into) - .map_err(RTCPeerConnectionError::SetRemoteDescriptionFailed) + .map_err(RtcPeerConnectionError::SetRemoteDescriptionFailed) .map_err(tracerr::wrap!())?; Ok(()) diff --git a/jason/src/platform/wasm/transport.rs b/jason/src/platform/wasm/transport.rs index 807b9b2dd..bad13b13f 100644 --- a/jason/src/platform/wasm/transport.rs +++ b/jason/src/platform/wasm/transport.rs @@ -17,7 +17,6 @@ use crate::{ wasm::utils::EventListener, }, rpc::{websocket::ClientDisconnect, ApiUrl, CloseMsg}, - utils::JasonError, }; /// Wrapper for help to get [`ServerMsg`] from Websocket [MessageEvent][1]. @@ -211,7 +210,7 @@ impl WebSocketRpcTransport { Err(e) => { // TODO: protocol versions mismatch? should drop // connection if so - JasonError::from(tracerr::new!(e)).print(); + log::error!("{}", tracerr::new!(e)); return; } }; diff --git a/jason/src/room.rs b/jason/src/room.rs index 22f7e186e..545522a09 100644 --- a/jason/src/room.rs +++ b/jason/src/room.rs @@ -1,8 +1,5 @@ //! Medea [`Room`]. -// TODO: Remove when moving `JasonError` to `api::wasm`. -#![allow(clippy::missing_errors_doc)] - use std::{ cell::RefCell, collections::{HashMap, HashSet}, @@ -26,6 +23,7 @@ use tracerr::Traced; use crate::{ api, + api::JasonError, connection::Connections, media::{ track::{local, remote}, @@ -42,7 +40,7 @@ use crate::{ ClientDisconnect, CloseReason, ConnectionInfo, ConnectionInfoParseError, ReconnectHandle, RpcSession, SessionError, }, - utils::{AsProtoState, HandlerDetachedError, JasonError, JsCaused}, + utils::{AsProtoState, JsCaused}, }; /// Reason of why [`Room`] has been closed. @@ -162,6 +160,14 @@ pub enum RoomError { /// [`peer::repo::Component`] returned [`MediaManagerError`]. #[display(fmt = "Failed to get local tracks: {}", _0)] MediaManagerError(#[js(cause)] MediaManagerError), + + /// [`ConnectionInfo`] parsing failed. + #[display(fmt = "Failed to parse ConnectionInfo: {}", _0)] + ConnectionInfoParse(ConnectionInfoParseError), + + /// [`RoomHandle`]'s [`Weak`] pointer is detached. + #[display(fmt = "Room is in detached state")] + Detached, } impl From for RoomError { @@ -184,6 +190,13 @@ impl From for RoomError { } } +macro_rules! upgrade_inner { + ($v:expr) => { + $v.upgrade() + .ok_or_else(|| tracerr::new!(RoomError::Detached)) + }; +} + /// External handle to a [`Room`]. #[derive(Clone)] pub struct RoomHandle(Weak); @@ -201,25 +214,31 @@ impl RoomHandle { /// /// # Errors /// - /// - When `on_failed_local_media` callback is not set. - /// - When `on_connection_loss` callback is not set. - /// - When unable to connect to a media server. - pub async fn join(&self, url: String) -> Result<(), JasonError> { - let inner = upgrade_or_detached!(self.0, JasonError)?; + /// With [`RoomError::CallbackNotSet`] if `on_failed_local_media` or + /// `on_connection_loss` callback is not set. + /// + /// With [`RoomError::ConnectionInfoParse`] if the provided URL parsing + /// fails. + /// + /// With [`RoomError::Detached`] if [`Weak`] pointer upgrade fails. + /// + /// With [`RoomError::SessionError`] when unable to connect to a media + /// server. + pub async fn join(&self, url: String) -> Result<(), Traced> { + let inner = upgrade_inner!(self.0)?; - let connection_info: ConnectionInfo = url.parse().map_err( - tracerr::map_from_and_wrap!(=> ConnectionInfoParseError), - )?; + let connection_info: ConnectionInfo = + url.parse().map_err(tracerr::map_from_and_wrap!())?; if !inner.on_failed_local_media.is_set() { - return Err(JasonError::from(tracerr::new!( - RoomError::CallbackNotSet("Room.on_failed_local_media()") + return Err(tracerr::new!(RoomError::CallbackNotSet( + "Room.on_failed_local_media()" ))); } if !inner.on_connection_loss.is_set() { - return Err(JasonError::from(tracerr::new!( - RoomError::CallbackNotSet("Room.on_connection_loss()") + return Err(tracerr::new!(RoomError::CallbackNotSet( + "Room.on_connection_loss()" ))); } @@ -239,8 +258,8 @@ impl RoomHandle { kind: MediaKind, direction: TrackDirection, source_kind: Option, - ) -> Result<(), JasonError> { - let inner = upgrade_or_detached!(self.0, JasonError)?; + ) -> Result<(), Traced> { + let inner = upgrade_inner!(self.0)?; inner.set_constraints_media_state( new_state, kind, @@ -263,7 +282,7 @@ impl RoomHandle { inner .get_local_tracks(kind, source_kind) .await - .map_err(tracerr::map_from_and_wrap!(=> RoomError))? + .map_err(tracerr::map_from_and_wrap!())? } else { Vec::new() }; @@ -277,7 +296,7 @@ impl RoomHandle { if let Err(e) = inner .toggle_media_state(new_state, kind, direction, source_kind) .await - .map_err(tracerr::map_from_and_wrap!(=> RoomError)) + .map_err(tracerr::map_from_and_wrap!()) { if direction_send && enabling { inner.set_constraints_media_state( @@ -295,7 +314,7 @@ impl RoomHandle { ) .await?; } - return Err(e.into()); + return Err(e); } } Ok(()) @@ -304,22 +323,30 @@ impl RoomHandle { /// Sets callback, invoked when a new [`Connection`] with some remote `Peer` /// is established. /// + /// # Errors + /// + /// With [`RoomError::Detached`] if [`Weak`] pointer upgrade fails. + /// /// [`Connection`]: crate::connection::Connection pub fn on_new_connection( &self, f: platform::Function, - ) -> Result<(), JasonError> { - upgrade_or_detached!(self.0) + ) -> Result<(), Traced> { + upgrade_inner!(self.0) .map(|inner| inner.connections.on_new_connection(f)) } /// Sets `on_close` callback, invoked on this [`Room`] close, providing a /// [`RoomCloseReason`]. + /// + /// # Errors + /// + /// With [`RoomError::Detached`] if [`Weak`] pointer upgrade fails. pub fn on_close( &self, f: platform::Function, - ) -> Result<(), JasonError> { - upgrade_or_detached!(self.0).map(|inner| inner.on_close.set_func(f)) + ) -> Result<(), Traced> { + upgrade_inner!(self.0).map(|inner| inner.on_close.set_func(f)) } /// Sets callback, invoked when a new [`local::Track`] is added to this @@ -329,32 +356,42 @@ impl RoomHandle { /// 1. Media server initiates a media request. /// 2. `disable_audio`/`enable_video` is called. /// 3. [`MediaStreamSettings`] updated via `set_local_media_settings`. + /// + /// # Errors + /// + /// With [`RoomError::Detached`] if [`Weak`] pointer upgrade fails. pub fn on_local_track( &self, f: platform::Function, - ) -> Result<(), JasonError> { - upgrade_or_detached!(self.0) - .map(|inner| inner.on_local_track.set_func(f)) + ) -> Result<(), Traced> { + upgrade_inner!(self.0).map(|inner| inner.on_local_track.set_func(f)) } /// Sets `on_failed_local_media` callback, invoked on a local media /// acquisition failures. + /// + /// # Errors + /// + /// With [`RoomError::Detached`] if [`Weak`] pointer upgrade fails. pub fn on_failed_local_media( &self, f: platform::Function, - ) -> Result<(), JasonError> { - upgrade_or_detached!(self.0) + ) -> Result<(), Traced> { + upgrade_inner!(self.0) .map(|inner| inner.on_failed_local_media.set_func(f)) } /// Sets `on_connection_loss` callback, invoked when a connection with /// server is lost. + /// + /// # Errors + /// + /// With [`RoomError::Detached`] if [`Weak`] pointer upgrade fails. pub fn on_connection_loss( &self, f: platform::Function, - ) -> Result<(), JasonError> { - upgrade_or_detached!(self.0) - .map(|inner| inner.on_connection_loss.set_func(f)) + ) -> Result<(), Traced> { + upgrade_inner!(self.0).map(|inner| inner.on_connection_loss.set_func(f)) } /// Updates this [`Room`]s [`MediaStreamSettings`]. This affects all @@ -380,6 +417,17 @@ impl RoomHandle { /// If recovering from fail state isn't possible then affected media types /// will be disabled. /// + /// # Errors + /// + /// With [`ConstraintsUpdateException::Errored`] if and error has occurred + /// while applying the provided [`MediaStreamSettings`]. + /// + /// With [`ConstraintsUpdateException::Recovered`] if + /// [`MediaStreamSettings`] are rolled-back because an error had occurred. + /// + /// With [`ConstraintsUpdateException::RecoverFailed`] if + /// [`MediaStreamSettings`] rollback failed. + /// /// [1]: https://tinyurl.com/w3-streams#dom-mediadevices-getusermedia pub async fn set_local_media_settings( &self, @@ -388,8 +436,8 @@ impl RoomHandle { rollback_on_fail: bool, ) -> Result<(), ConstraintsUpdateException> { let inner = (self.0).upgrade().ok_or_else(|| { - ConstraintsUpdateException::Errored(new_js_error!( - HandlerDetachedError + ConstraintsUpdateException::Errored(tracerr::new!( + RoomError::Detached )) })?; @@ -399,8 +447,8 @@ impl RoomHandle { .map_err(ConstraintsUpdateException::from) } - /// Changes a [`MediaState`] of the provided [`MediaKind`], - /// [`TrackDirection`] and [`MediaSourceKind`] to the provided one. + /// Changes [`MediaState`] of the provided [`MediaKind`], [`TrackDirection`] + /// and [`MediaSourceKind`] to the provided [`MediaState`]. /// /// Helper function for all the exported mute/unmute/enable/disable /// audio/video send/receive methods. @@ -411,7 +459,7 @@ impl RoomHandle { kind: MediaKind, direction: TrackDirection, source_kind: Option, - ) -> Result<(), JasonError> + ) -> Result<(), Traced> where S: Into + 'static, { @@ -422,11 +470,21 @@ impl RoomHandle { source_kind.map(Into::into), ) .await + .map_err(tracerr::wrap!()) } /// Mutes outbound audio in this [`Room`]. + /// + /// # Errors + /// + /// With [`RoomError::Detached`] if an inner [`Weak`] pointer upgrade fails. + /// + /// With [`RoomError::MediaConnections`] with + /// [`MediaConnectionsError::MediaStateTransitsIntoOppositeState`] if + /// [`RoomHandle::unmute_audio()`] was called while muting or a media server + /// didn't approve this state transition. #[inline] - pub async fn mute_audio(&self) -> Result<(), JasonError> { + pub async fn mute_audio(&self) -> Result<(), Traced> { self.change_media_state( mute_state::Stable::Muted, MediaKind::Audio, @@ -434,11 +492,21 @@ impl RoomHandle { None, ) .await + .map_err(tracerr::map_from_and_wrap!()) } /// Unmutes outbound audio in this [`Room`]. + /// + /// # Errors + /// + /// With [`RoomError::Detached`] if an inner [`Weak`] pointer upgrade fails. + /// + /// With [`RoomError::MediaConnections`] with + /// [`MediaConnectionsError::MediaStateTransitsIntoOppositeState`] if + /// [`RoomHandle::mute_audio`] was called while muting or a media server + /// didn't approve this state transition. #[inline] - pub async fn unmute_audio(&self) -> Result<(), JasonError> { + pub async fn unmute_audio(&self) -> Result<(), Traced> { self.change_media_state( mute_state::Stable::Unmuted, MediaKind::Audio, @@ -446,14 +514,24 @@ impl RoomHandle { None, ) .await + .map_err(tracerr::map_from_and_wrap!()) } /// Mutes outbound video in this [`Room`]. + /// + /// # Errors + /// + /// With [`RoomError::Detached`] if an inner [`Weak`] pointer upgrade fails. + /// + /// With [`RoomError::MediaConnections`] with + /// [`MediaConnectionsError::MediaStateTransitsIntoOppositeState`] if + /// [`RoomHandle::unmute_video()`] was called while muting or a media server + /// didn't approve this state transition. #[inline] pub async fn mute_video( &self, source_kind: Option, - ) -> Result<(), JasonError> { + ) -> Result<(), Traced> { self.change_media_state( mute_state::Stable::Muted, MediaKind::Video, @@ -461,14 +539,24 @@ impl RoomHandle { source_kind, ) .await + .map_err(tracerr::map_from_and_wrap!()) } /// Unmutes outbound video in this [`Room`]. + /// + /// # Errors + /// + /// With [`RoomError::Detached`] if an inner [`Weak`] pointer upgrade fails. + /// + /// With [`RoomError::MediaConnections`] with + /// [`MediaConnectionsError::MediaStateTransitsIntoOppositeState`] if + /// [`RoomHandle::mute_video()`] was called while muting or a media server + /// didn't approve this state transition. #[inline] pub async fn unmute_video( &self, source_kind: Option, - ) -> Result<(), JasonError> { + ) -> Result<(), Traced> { self.change_media_state( mute_state::Stable::Unmuted, MediaKind::Video, @@ -476,11 +564,25 @@ impl RoomHandle { source_kind, ) .await + .map_err(tracerr::map_from_and_wrap!()) } /// Disables outbound audio in this [`Room`]. + /// + /// # Errors + /// + /// With [`RoomError::Detached`] if an inner [`Weak`] pointer upgrade fails. + /// + /// With [`RoomError::MediaConnections`] with + /// [`MediaConnectionsError::CannotDisableRequiredSender`] if audio track's + /// sender is configured as `required`. + /// + /// With [`RoomError::MediaConnections`] with + /// [`MediaConnectionsError::MediaStateTransitsIntoOppositeState`] if + /// [`RoomHandle::enable_audio()`] was called while disabling or a media + /// server didn't approve this state transition. #[inline] - pub async fn disable_audio(&self) -> Result<(), JasonError> { + pub async fn disable_audio(&self) -> Result<(), Traced> { self.change_media_state( media_exchange_state::Stable::Disabled, MediaKind::Audio, @@ -488,11 +590,26 @@ impl RoomHandle { None, ) .await + .map_err(tracerr::map_from_and_wrap!()) } /// Enables outbound audio in this [`Room`]. + /// + /// # Errors + /// + /// With [`RoomError::Detached`] if an inner [`Weak`] pointer upgrade fails. + /// + /// With [`RoomError::MediaConnections`] with + /// [`MediaConnectionsError::MediaStateTransitsIntoOppositeState`] if + /// [`RoomHandle::disable_audio`] was called while enabling or a media + /// server didn't approve this state transition. + /// + /// With [`RoomError::MediaManagerError`] with + /// [`MediaManagerError::CouldNotGetMediaDevices`] or + /// [`MediaManagerError::GetUserMediaFailed`] if media acquisition request + /// failed. #[inline] - pub async fn enable_audio(&self) -> Result<(), JasonError> { + pub async fn enable_audio(&self) -> Result<(), Traced> { self.change_media_state( media_exchange_state::Stable::Enabled, MediaKind::Audio, @@ -500,16 +617,30 @@ impl RoomHandle { None, ) .await + .map_err(tracerr::map_from_and_wrap!()) } /// Disables outbound video. /// /// Affects only video with specific [`MediaSourceKind`] if specified. + /// + /// # Errors + /// + /// With [`RoomError::Detached`] if an inner [`Weak`] pointer upgrade fails. + /// + /// With [`RoomError::MediaConnections`] with + /// [`MediaConnectionsError::CannotDisableRequiredSender`] video track's + /// sender is configured as `required`. + /// + /// With [`RoomError::MediaConnections`] with + /// [`MediaConnectionsError::MediaStateTransitsIntoOppositeState`] if + /// [`RoomHandle::enable_video()`] was called while disabling or a media + /// server didn't approve this state transition. #[inline] pub async fn disable_video( &self, source_kind: Option, - ) -> Result<(), JasonError> { + ) -> Result<(), Traced> { self.change_media_state( media_exchange_state::Stable::Disabled, MediaKind::Video, @@ -517,16 +648,31 @@ impl RoomHandle { source_kind, ) .await + .map_err(tracerr::map_from_and_wrap!()) } /// Enables outbound video. /// /// Affects only video with specific [`MediaSourceKind`] if specified. + /// + /// # Errors + /// + /// With [`RoomError::Detached`] if an inner [`Weak`] pointer upgrade fails. + /// + /// With [`RoomError::MediaConnections`] with + /// [`MediaConnectionsError::MediaStateTransitsIntoOppositeState`] if + /// [`RoomHandle::disable_video()`] was called while enabling or a media + /// server didn't approve this state transition. + /// + /// With [`RoomError::MediaManagerError`] with + /// [`MediaManagerError::CouldNotGetMediaDevices`] or + /// [`MediaManagerError::GetUserMediaFailed`] if media acquisition request + /// failed. #[inline] pub async fn enable_video( &self, source_kind: Option, - ) -> Result<(), JasonError> { + ) -> Result<(), Traced> { self.change_media_state( media_exchange_state::Stable::Enabled, MediaKind::Video, @@ -534,11 +680,21 @@ impl RoomHandle { source_kind, ) .await + .map_err(tracerr::map_from_and_wrap!()) } /// Disables inbound audio in this [`Room`]. + /// + /// # Errors + /// + /// With [`RoomError::Detached`] if an inner [`Weak`] pointer upgrade fails. + /// + /// With [`RoomError::MediaConnections`] with + /// [`MediaConnectionsError::MediaStateTransitsIntoOppositeState`] if + /// [`RoomHandle::enable_remote_audio()`] was called while disabling or a + /// media server didn't approve this state transition. #[inline] - pub async fn disable_remote_audio(&self) -> Result<(), JasonError> { + pub async fn disable_remote_audio(&self) -> Result<(), Traced> { self.change_media_state( media_exchange_state::Stable::Disabled, MediaKind::Audio, @@ -546,11 +702,21 @@ impl RoomHandle { None, ) .await + .map_err(tracerr::map_from_and_wrap!()) } /// Disables inbound video in this [`Room`]. + /// + /// # Errors + /// + /// With [`RoomError::Detached`] if an inner [`Weak`] pointer upgrade fails. + /// + /// With [`RoomError::MediaConnections`] with + /// [`MediaConnectionsError::MediaStateTransitsIntoOppositeState`] if + /// [`RoomHandle::enable_remote_video()`] was called while disabling or a + /// media server didn't approve this state transition. #[inline] - pub async fn disable_remote_video(&self) -> Result<(), JasonError> { + pub async fn disable_remote_video(&self) -> Result<(), Traced> { self.change_media_state( media_exchange_state::Stable::Disabled, MediaKind::Video, @@ -558,11 +724,21 @@ impl RoomHandle { None, ) .await + .map_err(tracerr::map_from_and_wrap!()) } /// Enables inbound audio in this [`Room`]. + /// + /// # Errors + /// + /// With [`RoomError::Detached`] if an inner [`Weak`] pointer upgrade fails. + /// + /// With [`RoomError::MediaConnections`] with + /// [`MediaConnectionsError::MediaStateTransitsIntoOppositeState`] if + /// [`RoomHandle::disable_remote_audio()`] was called while enabling or a + /// media server didn't approve this state transition. #[inline] - pub async fn enable_remote_audio(&self) -> Result<(), JasonError> { + pub async fn enable_remote_audio(&self) -> Result<(), Traced> { self.change_media_state( media_exchange_state::Stable::Enabled, MediaKind::Audio, @@ -570,11 +746,21 @@ impl RoomHandle { None, ) .await + .map_err(tracerr::map_from_and_wrap!()) } /// Enables inbound video in this [`Room`]. + /// + /// # Errors + /// + /// With [`RoomError::Detached`] if an inner [`Weak`] pointer upgrade fails. + /// + /// With [`RoomError::MediaConnections`] with + /// [`MediaConnectionsError::MediaStateTransitsIntoOppositeState`] if + /// [`RoomHandle::disable_remote_video()`] was called while enabling or a + /// media server didn't approve this state transition. #[inline] - pub async fn enable_remote_video(&self) -> Result<(), JasonError> { + pub async fn enable_remote_video(&self) -> Result<(), Traced> { self.change_media_state( media_exchange_state::Stable::Enabled, MediaKind::Video, @@ -582,6 +768,7 @@ impl RoomHandle { None, ) .await + .map_err(tracerr::map_from_and_wrap!()) } } @@ -648,17 +835,25 @@ impl Room { if let Some(inner) = inner.upgrade() { match event { RoomEvent::RpcEvent(event) => { - if let Err(err) = - event.dispatch_with(inner.deref()).await + if let Err(e) = event + .dispatch_with(inner.deref()) + .await + .map_err( + tracerr::map_from_and_wrap!(=> RoomError), + ) { - JasonError::from(err).print(); + log::error!("{}", e); }; } RoomEvent::PeerEvent(event) => { - if let Err(err) = - event.dispatch_with(inner.deref()).await + if let Err(e) = event + .dispatch_with(inner.deref()) + .await + .map_err( + tracerr::map_from_and_wrap!(=> RoomError), + ) { - JasonError::from(err).print(); + log::error!("{}", e); }; } RoomEvent::RpcClientLostConnection => { @@ -780,24 +975,24 @@ pub enum ConstraintsUpdateException { /// (`rollback_on_fail`/`stop_first` arguments). #[display(fmt = "RecoveredException")] Recovered { - /// [`JasonError`] due to which recovery happened. - recover_reason: JasonError, + /// [`RoomError`] due to which recovery has happened. + recover_reason: Traced, }, /// New [`MediaStreamSettings`] set failed and state recovering also /// failed. #[display(fmt = "RecoverFailedException")] RecoverFailed { - /// [`JasonError`] due to which recovery happened. - recover_reason: JasonError, + /// [`RoomError`] due to which recovery has happened. + recover_reason: Traced, - /// Vector of [`JasonError`]s due to which recovery failed. - recover_fail_reasons: Vec, + /// Vector of [`RoomError`]s due to which recovery has failed. + recover_fail_reasons: Vec>, }, /// Some other error occurred. #[display(fmt = "ErroredException")] - Errored(JasonError), + Errored(Traced), } impl ConstraintsUpdateException { @@ -808,13 +1003,13 @@ impl ConstraintsUpdateException { self.to_string() } - /// Returns [`JasonError`] if this [`ConstraintsUpdateException`] represents - /// a `RecoveredException` or a `RecoverFailedException`. + /// Returns a [`RoomError`] if this [`ConstraintsUpdateException`] + /// represents a `RecoveredException` or a `RecoverFailedException`. /// /// Returns `undefined` otherwise. #[inline] #[must_use] - pub fn recover_reason(&self) -> Option { + pub fn recover_reason(&self) -> Option> { match &self { Self::RecoverFailed { recover_reason, .. } | Self::Recovered { recover_reason, .. } => { @@ -824,10 +1019,10 @@ impl ConstraintsUpdateException { } } - /// Returns a list of [`JasonError`]s due to which a recovery has failed. + /// Returns a list of [`RoomError`]s due to which a recovery has failed. #[inline] #[must_use] - pub fn recover_fail_reasons(&self) -> Vec { + pub fn recover_fail_reasons(&self) -> Vec> { match &self { Self::RecoverFailed { recover_fail_reasons, @@ -837,13 +1032,13 @@ impl ConstraintsUpdateException { } } - /// Returns [`JasonError`] if this [`ConstraintsUpdateException`] represents - /// an `ErroredException`. + /// Returns a [`RoomError`] if this [`ConstraintsUpdateException`] + /// represents an `ErroredException`. /// /// Returns `undefined` otherwise. #[inline] #[must_use] - pub fn error(&self) -> Option { + pub fn error(&self) -> Option> { match &self { Self::Errored(reason) => Some(reason.clone()), _ => None, @@ -920,22 +1115,22 @@ impl From for ConstraintsUpdateException { use ConstraintsUpdateError as E; match from { E::Recovered { recover_reason } => Self::Recovered { - recover_reason: JasonError::from(recover_reason), + recover_reason: tracerr::new!(recover_reason), }, E::RecoverFailed { recover_reason, recover_fail_reasons, } => Self::RecoverFailed { - recover_reason: JasonError::from(recover_reason), + recover_reason: tracerr::new!(recover_reason), recover_fail_reasons: { recover_fail_reasons .into_iter() - .map(JasonError::from) + .map(tracerr::map_from_and_wrap!()) .collect() }, }, E::Errored { error: reason } => { - Self::Errored(JasonError::from(reason)) + Self::Errored(tracerr::new!(reason)) } } } diff --git a/jason/src/rpc/mod.rs b/jason/src/rpc/mod.rs index 93ca51550..a6c464b01 100644 --- a/jason/src/rpc/mod.rs +++ b/jason/src/rpc/mod.rs @@ -23,7 +23,7 @@ pub use self::rpc_session::MockRpcSession; pub use self::{ backoff_delayer::BackoffDelayer, heartbeat::{Heartbeat, HeartbeatError, IdleTimeout, PingInterval}, - reconnect_handle::ReconnectHandle, + reconnect_handle::{ReconnectError, ReconnectHandle}, rpc_session::{ RpcSession, SessionError, SessionState, WebSocketRpcSession, }, @@ -75,7 +75,7 @@ impl ConnectionInfo { } /// Errors which can occur while [`ConnectionInfo`] parsing from the [`str`]. -#[derive(Debug, JsCaused, Display)] +#[derive(Clone, Debug, Display, JsCaused)] #[js(error = "platform::Error")] pub enum ConnectionInfoParseError { /// [`Url::parse`] returned error. diff --git a/jason/src/rpc/reconnect_handle.rs b/jason/src/rpc/reconnect_handle.rs index 41ffa0c1f..5a1359d1e 100644 --- a/jason/src/rpc/reconnect_handle.rs +++ b/jason/src/rpc/reconnect_handle.rs @@ -1,23 +1,28 @@ //! Reconnection for [`RpcSession`]. -// TODO: Remove when moving `JasonError` to `api::wasm`. -#![allow(clippy::missing_errors_doc)] - use std::{rc::Weak, time::Duration}; -use derive_more::Display; +use derive_more::{Display, From}; +use tracerr::Traced; use crate::{ platform, - rpc::{BackoffDelayer, RpcSession}, - utils::{HandlerDetachedError, JasonError, JsCaused}, + rpc::{BackoffDelayer, RpcSession, SessionError}, + utils::JsCaused, }; -/// Error which indicates that [`RpcSession`]'s (which this [`ReconnectHandle`] -/// tries to reconnect) token is `None`. -#[derive(Debug, Display, JsCaused)] +/// Errors occurring in a [`ReconnectHandle`]. +#[derive(Clone, From, Display, JsCaused)] #[js(error = "platform::Error")] -struct NoTokenError; +pub enum ReconnectError { + /// Some [`SessionError`] has occurred while reconnecting. + #[display(fmt = "{}", _0)] + Session(#[js(cause)] SessionError), + + /// [`ReconnectHandle`]'s [`Weak`] pointer is detached. + #[display(fmt = "Reconnector is in detached state")] + Detached, +} /// External handle used to reconnect to a media server when connection is lost. /// @@ -39,16 +44,25 @@ impl ReconnectHandle { /// If [`RpcSession`] is already reconnecting then new reconnection attempt /// won't be performed. Instead, it will wait for the first reconnection /// attempt result and use it here. + /// + /// # Errors + /// + /// With [`ReconnectError::Detached`] if [`Weak`] pointer upgrade fails. + /// + /// With [`ReconnectError::Session`] if error while reconnecting has + /// occurred. pub async fn reconnect_with_delay( &self, delay_ms: u32, - ) -> Result<(), JasonError> { + ) -> Result<(), Traced> { platform::delay_for(Duration::from_millis(u64::from(delay_ms))).await; - let rpc = upgrade_or_detached!(self.0, JasonError)?; - rpc.reconnect().await.map_err(JasonError::from)?; + let rpc = self + .0 + .upgrade() + .ok_or_else(|| tracerr::new!(ReconnectError::Detached))?; - Ok(()) + rpc.reconnect().await.map_err(tracerr::map_from_and_wrap!()) } /// Tries to reconnect [`RpcSession`] in a loop with a growing backoff @@ -69,19 +83,26 @@ impl ReconnectHandle { /// /// If `multiplier` is negative number than `multiplier` will be considered /// as `0.0`. + /// + /// # Errors + /// + /// With [`ReconnectError::Detached`] if [`Weak`] pointer upgrade fails. pub async fn reconnect_with_backoff( &self, starting_delay_ms: u32, multiplier: f32, max_delay: u32, - ) -> Result<(), JasonError> { + ) -> Result<(), Traced> { let mut backoff_delayer = BackoffDelayer::new( Duration::from_millis(u64::from(starting_delay_ms)), multiplier, Duration::from_millis(u64::from(max_delay)), ); backoff_delayer.delay().await; - while upgrade_or_detached!(self.0, JasonError)? + while self + .0 + .upgrade() + .ok_or_else(|| tracerr::new!(ReconnectError::Detached))? .reconnect() .await .is_err() diff --git a/jason/src/rpc/websocket/client.rs b/jason/src/rpc/websocket/client.rs index e37f5ad94..ee26b38c2 100644 --- a/jason/src/rpc/websocket/client.rs +++ b/jason/src/rpc/websocket/client.rs @@ -21,7 +21,6 @@ use crate::{ ApiUrl, CloseMsg, CloseReason, ClosedStateReason, Heartbeat, IdleTimeout, PingInterval, RpcClientError, }, - utils::JasonError, }; /// Reasons of closing WebSocket RPC connection by a client side. @@ -525,10 +524,11 @@ impl WebSocketRpcClient { let socket_borrow = &self.0.borrow().sock; if let Some(socket) = socket_borrow.as_ref() { - if let Err(err) = - socket.send(&ClientMsg::Command { room_id, command }) + if let Err(e) = socket + .send(&ClientMsg::Command { room_id, command }) + .map_err(tracerr::map_from_and_wrap!(=> RpcClientError)) { - JasonError::from(err).print() + log::error!("{}", e); } } } diff --git a/jason/src/utils/component.rs b/jason/src/utils/component.rs index 3814dcb9d..06ebe4c1c 100644 --- a/jason/src/utils/component.rs +++ b/jason/src/utils/component.rs @@ -1,16 +1,12 @@ //! Implementation of the [`Component`]. -use std::rc::Rc; +use std::{fmt::Display, rc::Rc}; use derive_more::Deref; use futures::{future, Future, FutureExt as _, Stream, StreamExt}; use medea_reactive::AllProcessed; -use crate::{ - media::LocalTracksConstraints, - platform, - utils::{JasonError, TaskHandle}, -}; +use crate::{media::LocalTracksConstraints, platform, utils::TaskHandle}; /// Abstraction over a state which can be transformed to the states from the /// [`medea_client_api_proto::state`]. @@ -114,8 +110,8 @@ pub struct WatchersSpawner { impl WatchersSpawner { /// Spawns watchers for the provided [`Stream`]. /// - /// If watcher returns an error then this error will be converted into the - /// [`JasonError`] and printed with a [`JasonError::print()`]. + /// If watcher returns an error then this error will be printed to the error + /// log. /// /// You can stop all listeners tasks spawned by this function by /// [`Drop`]ping [`Component`]. @@ -124,7 +120,7 @@ impl WatchersSpawner { F: Fn(Rc, Rc, V) -> H + 'static, R: Stream + Unpin + 'static, H: Future> + 'static, - E: Into, + E: Display, { let obj = Rc::clone(&self.obj); let state = Rc::clone(&self.state); @@ -133,7 +129,7 @@ impl WatchersSpawner { if let Err(e) = (handle)(Rc::clone(&obj), Rc::clone(&state), value).await { - Into::::into(e).print(); + log::error!("{}", e); } } }); diff --git a/jason/src/utils/errors.rs b/jason/src/utils/errors.rs index ab62ecfb2..6ed11c4c2 100644 --- a/jason/src/utils/errors.rs +++ b/jason/src/utils/errors.rs @@ -1,14 +1,8 @@ //! Helpers for application errors. -use std::{ - fmt::{Debug, Display}, - rc::Rc, -}; +use std::{fmt::Debug, rc::Rc}; use derive_more::{Display, From}; -use tracerr::{Trace, Traced}; - -use crate::platform; pub use medea_macro::JsCaused; @@ -25,82 +19,6 @@ pub trait JsCaused { fn js_cause(self) -> Option; } -// TODO: Consider moving to `api::wasm`. -/// Abstract application error. -#[derive(Clone, Debug, Display)] -#[display(fmt = "{}: {}\n{}", name, message, trace)] -pub struct JasonError { - name: &'static str, - message: String, - trace: Trace, - source: Option, -} - -impl JasonError { - /// Returns name of this error. - #[inline] - #[must_use] - pub fn name(&self) -> String { - String::from(self.name) - } - - /// Returns message of this error. - #[inline] - #[must_use] - pub fn message(&self) -> String { - self.message.clone() - } - - /// Returns trace information of this error. - #[inline] - #[must_use] - pub fn trace(&self) -> String { - self.trace.to_string() - } - - /// Returns [`platform::Error`] if it's the cause. - #[inline] - #[must_use] - pub fn source(&self) -> Option { - Clone::clone(&self.source) - } - - /// Prints error information to default logger with an `ERROR` level. - #[inline] - pub fn print(&self) { - log::error!("{}", self); - } -} - -impl From<(E, Trace)> for JasonError -where - E::Error: Into, -{ - fn from((err, trace): (E, Trace)) -> Self { - Self { - name: err.name(), - message: err.to_string(), - trace, - source: err.js_cause().map(Into::into), - } - } -} - -impl From> for JasonError -where - E::Error: Into, -{ - fn from(traced: Traced) -> Self { - Self::from(traced.into_parts()) - } -} - -/// Occurs if referenced value was dropped. -#[derive(Debug, Display, JsCaused)] -#[display(fmt = "Handler is in detached state.")] -#[js(error = "platform::Error")] -pub struct HandlerDetachedError; - /// Wrapper for [`serde_json::error::Error`] that provides [`Clone`], [`Debug`], /// [`Display`] implementations. #[derive(Clone, Debug, Display, From)] diff --git a/jason/src/utils/mod.rs b/jason/src/utils/mod.rs index a6a666d0f..e331d13ca 100644 --- a/jason/src/utils/mod.rs +++ b/jason/src/utils/mod.rs @@ -15,44 +15,10 @@ use medea_reactive::Guarded; #[doc(inline)] pub use self::{ component::{AsProtoState, Component, SynchronizableState, Updatable}, - errors::{HandlerDetachedError, JasonError, JsCaused, JsonParseError}, + errors::{JsCaused, JsonParseError}, resettable_delay::{resettable_delay_for, ResettableDelayHandle}, }; -/// Upgrades provided [`Weak`] reference, mapping it to a [`Result`] with -/// [`HandlerDetachedError`] and invokes [`Into::into`] on the error. -/// If the error type cannot be inferred, then you can provide a concrete type -/// (usually being [`JasonError`] or [`JsValue`]). -/// -/// [`Weak`]: std::rc::Weak -macro_rules! upgrade_or_detached { - ($v:expr) => {{ - $v.upgrade() - .ok_or_else(|| new_js_error!(HandlerDetachedError)) - }}; - ($v:expr, $err:ty) => {{ - $v.upgrade() - .ok_or_else(|| new_js_error!(HandlerDetachedError => $err)) - }}; -} - -/// Adds [`tracerr`] information to the provided error, wraps it into -/// [`JasonError`] and converts it into the expected error type. -/// -/// This macro has two syntaxes: -/// - `new_js_error!(DetachedStateError)` - converts provided error wrapped into -/// [`JasonError`] with [`Into::into`] automatically; -/// - `new_js_error!(DetachedStateError => platform::Error)` - annotates -/// explicitly which type conversion is required. -macro_rules! new_js_error { - ($e:expr) => { - $crate::utils::JasonError::from(tracerr::new!($e)).into() - }; - ($e:expr => $o:ty) => { - <$o>::from($crate::utils::JasonError::from(tracerr::new!($e))) - }; -} - /// Wrapper around [`AbortHandle`] which aborts [`Future`] on [`Drop`]. /// /// [`Future`]: std::future::Future