Skip to content

Commit 408be2c

Browse files
committed
fix(material/core): throw better error messages from typography utils (#27393)
Currently the typography functions assume that a config and the level being looked up will exist, but that's not necessarily the case which leads to some cryptic error messages that take a while to parse. These changes add some validations so that it's easier to figure out what's wrong. (cherry picked from commit b985c7d)
1 parent 69eff19 commit 408be2c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/material/core/typography/_typography-utils.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77

88
// Utility for fetching a nested value from a typography config.
99
@function _mat-get-type-value($config, $level, $name) {
10+
@if meta.type-of($config) != 'map' {
11+
@error 'Typography config must be a map. Received #{meta.type-of($config)}.';
12+
}
13+
14+
@if not map.has-key($config, $level) {
15+
@error 'Typography config does not have a level called "#{$level}". ' +
16+
'Available levels are: #{map.keys($config)}.';
17+
}
18+
1019
@return map.get(map.get($config, $level), $name);
1120
}
1221

@@ -42,6 +51,10 @@
4251
/// @param {Map} $config A typography config.
4352
/// @param {Map} $level A typography level.
4453
@function font-family($config, $level: null) {
54+
@if meta.type-of($config) != 'map' {
55+
@error 'Typography config must be a map. Received #{meta.type-of($config)}.';
56+
}
57+
4558
$font-family: map.get($config, font-family);
4659

4760
@if $level != null {

0 commit comments

Comments
 (0)