Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[getContrastText] Throw descriptive exception when passing falsy argument #18383

Merged
merged 1 commit into from
Nov 15, 2019

Conversation

eps1lon
Copy link
Member

@eps1lon eps1lon commented Nov 15, 2019

The problem with console.error is that it is oftentimes overlooked. When we know that an exception will be thrown if we continue we might as well throw ourselves with the benefit of:

  1. having a single error message in the console instead of 2
  2. a more accurate stack trace (pointing to the line where the dev can change something instead of inside the internal stack)
  3. a descriptive error message in the error overlay

@eps1lon eps1lon added new feature New feature or request package: material-ui Specific to @mui/material labels Nov 15, 2019
@mui-pr-bot
Copy link

Details of bundle changes.

Comparing: 384d61a...636b203

bundle Size Change Size Gzip Change Gzip
SwipeableDrawer ▲ +105 B (+0.12% ) 90.2 kB ▲ +50 B (+0.18% ) 28 kB
Tabs ▲ +105 B (+0.13% ) 83.9 kB ▲ +49 B (+0.18% ) 26.7 kB
Slider ▲ +105 B (+0.14% ) 74.1 kB ▲ +48 B (+0.21% ) 23.4 kB
Divider ▲ +105 B (+0.17% ) 61.1 kB ▲ +47 B (+0.25% ) 19.2 kB
Checkbox ▲ +105 B (+0.13% ) 80.3 kB ▲ +46 B (+0.18% ) 25.2 kB
DialogTitle ▲ +105 B (+0.17% ) 62.8 kB ▲ +44 B (+0.22% ) 19.7 kB
GridListTileBar ▲ +105 B (+0.17% ) 61.8 kB ▲ +44 B (+0.23% ) 19.3 kB
ButtonGroup ▲ +105 B (+0.13% ) 80.5 kB ▲ +43 B (+0.17% ) 24.7 kB
DialogContent ▲ +105 B (+0.17% ) 60.8 kB ▲ +43 B (+0.23% ) 19 kB
Step ▲ +105 B (+0.17% ) 61.1 kB ▲ +43 B (+0.22% ) 19.2 kB
DialogContentText ▲ +105 B (+0.17% ) 62.6 kB ▲ +42 B (+0.21% ) 19.6 kB
GridListTile ▲ +105 B (+0.17% ) 62.3 kB ▲ +42 B (+0.22% ) 19.5 kB
Radio ▲ +105 B (+0.13% ) 81.1 kB ▲ +42 B (+0.17% ) 25.5 kB
CardActionArea ▲ +105 B (+0.14% ) 73.5 kB ▲ +41 B (+0.18% ) 23.2 kB
CardActions ▲ +105 B (+0.17% ) 60.6 kB ▲ +41 B (+0.22% ) 19 kB
CardContent ▲ +105 B (+0.17% ) 60.5 kB ▲ +41 B (+0.22% ) 18.9 kB
CardHeader ▲ +105 B (+0.17% ) 63.6 kB ▲ +41 B (+0.21% ) 20 kB
Grid ▲ +105 B (+0.17% ) 63.6 kB ▲ +41 B (+0.21% ) 19.9 kB
ListItemAvatar ▲ +105 B (+0.17% ) 60.6 kB ▲ +41 B (+0.22% ) 19 kB
ListItemSecondaryAction ▲ +105 B (+0.17% ) 60.5 kB ▲ +41 B (+0.22% ) 18.9 kB
StepButton ▲ +105 B (+0.13% ) 80.8 kB ▲ +41 B (+0.16% ) 25.3 kB
Table ▲ +105 B (+0.17% ) 61.1 kB ▲ +41 B (+0.21% ) 19.1 kB
TableBody ▲ +105 B (+0.17% ) 60.6 kB ▲ +41 B (+0.22% ) 19 kB
TableHead ▲ +105 B (+0.17% ) 60.6 kB ▲ +41 B (+0.22% ) 19 kB
BottomNavigationAction ▲ +105 B (+0.14% ) 74 kB ▲ +40 B (+0.17% ) 23.4 kB
CardMedia ▲ +105 B (+0.17% ) 60.9 kB ▲ +40 B (+0.21% ) 19.1 kB
DialogActions ▲ +105 B (+0.17% ) 60.6 kB ▲ +40 B (+0.21% ) 19 kB
Drawer ▲ +105 B (+0.13% ) 82.8 kB ▲ +40 B (+0.16% ) 25.6 kB
ExpansionPanelActions ▲ +105 B (+0.17% ) 60.6 kB ▲ +40 B (+0.21% ) 19 kB
ExpansionPanelDetails ▲ +105 B (+0.17% ) 60.5 kB ▲ +40 B (+0.21% ) 18.9 kB
ExpansionPanelSummary ▲ +105 B (+0.14% ) 76.6 kB ▲ +40 B (+0.17% ) 24.1 kB
GridList ▲ +105 B (+0.17% ) 61 kB ▲ +40 B (+0.21% ) 19.1 kB
ListItemIcon ▲ +105 B (+0.17% ) 60.7 kB ▲ +40 B (+0.21% ) 19 kB
Menu ▲ +105 B (+0.12% ) 86.7 kB ▲ +40 B (+0.15% ) 27.2 kB
Skeleton ▲ +105 B (+0.17% ) 61 kB ▲ +40 B (+0.21% ) 19.2 kB
Stepper ▲ +105 B (+0.17% ) 63.3 kB ▲ +40 B (+0.20% ) 19.9 kB
TableFooter ▲ +105 B (+0.17% ) 60.6 kB ▲ +40 B (+0.21% ) 19 kB
TableRow ▲ +105 B (+0.17% ) 61.1 kB ▲ +40 B (+0.21% ) 19.1 kB
TreeView ▲ +105 B (+0.16% ) 64.9 kB ▲ +40 B (+0.20% ) 20.3 kB
CircularProgress ▲ +105 B (+0.17% ) 62.6 kB ▲ +39 B (+0.20% ) 19.7 kB
Container ▲ +105 B (+0.17% ) 61.7 kB ▲ +39 B (+0.20% ) 19.3 kB
Dialog ▲ +105 B (+0.13% ) 81.1 kB ▲ +39 B (+0.16% ) 25.1 kB
ListItemText ▲ +105 B (+0.17% ) 63.5 kB ▲ +39 B (+0.20% ) 20 kB
Snackbar ▲ +105 B (+0.14% ) 75.7 kB ▲ +39 B (+0.17% ) 23.6 kB
ToggleButtonGroup ▲ +105 B (+0.17% ) 61.7 kB ▲ +39 B (+0.20% ) 19.4 kB
FormControlLabel ▲ +105 B (+0.16% ) 64 kB ▲ +38 B (+0.19% ) 20.1 kB
InputAdornment ▲ +105 B (+0.17% ) 63.6 kB ▲ +38 B (+0.19% ) 20 kB
LinearProgress ▲ +105 B (+0.16% ) 63.9 kB ▲ +38 B (+0.19% ) 19.9 kB
Link ▲ +105 B (+0.16% ) 65.1 kB ▲ +38 B (+0.18% ) 20.6 kB
SpeedDialIcon ▲ +105 B (+0.17% ) 63.1 kB ▲ +38 B (+0.19% ) 19.8 kB
styles/createMuiTheme ▲ +105 B (+0.69% ) 15.3 kB ▲ +38 B (+0.71% ) 5.4 kB
Tab ▲ +105 B (+0.14% ) 74.8 kB ▲ +38 B (+0.16% ) 23.7 kB
CssBaseline ▲ +105 B (+0.19% ) 56.1 kB ▲ +37 B (+0.21% ) 17.5 kB
Hidden ▲ +105 B (+0.16% ) 64.5 kB ▲ +37 B (+0.18% ) 20.2 kB
Icon ▲ +105 B (+0.17% ) 61.3 kB ▲ +37 B (+0.19% ) 19.2 kB
SpeedDial ▲ +105 B (+0.12% ) 84.5 kB ▲ +37 B (+0.14% ) 26.6 kB
AppBar ▲ +105 B (+0.17% ) 62.3 kB ▲ +36 B (+0.18% ) 19.5 kB
Box ▲ +105 B (+0.15% ) 69.3 kB ▲ +36 B (+0.17% ) 21 kB
Card ▲ +105 B (+0.17% ) 61.3 kB ▲ +36 B (+0.19% ) 19.2 kB
Select ▲ +105 B (+0.09% ) 113 kB ▲ +36 B (+0.11% ) 33.4 kB
Slide ▲ +105 B (+0.44% ) 24.2 kB ▲ +36 B (+0.44% ) 8.24 kB
SpeedDialAction ▲ +105 B (+0.09% ) 115 kB ▲ +36 B (+0.10% ) 36.4 kB
Switch ▲ +105 B (+0.13% ) 79.6 kB ▲ +36 B (+0.15% ) 24.7 kB
TextField ▲ +105 B (+0.09% ) 121 kB ▲ +36 B (+0.10% ) 35.5 kB
Toolbar ▲ +105 B (+0.17% ) 60.9 kB ▲ +36 B (+0.19% ) 19.1 kB
TreeItem ▲ +105 B (+0.15% ) 72.1 kB ▲ +36 B (+0.16% ) 22.7 kB
Zoom ▲ +105 B (+0.48% ) 22.2 kB ▲ +36 B (+0.47% ) 7.64 kB
Autocomplete ▲ +105 B (+0.08% ) 126 kB ▲ +35 B (+0.09% ) 39.9 kB
BottomNavigation ▲ +105 B (+0.17% ) 60.9 kB ▲ +35 B (+0.18% ) 19.1 kB
Fade ▲ +105 B (+0.48% ) 22.1 kB ▲ +35 B (+0.46% ) 7.63 kB
FormGroup ▲ +105 B (+0.17% ) 60.5 kB ▲ +35 B (+0.19% ) 18.9 kB
FormHelperText ▲ +105 B (+0.17% ) 61.8 kB ▲ +35 B (+0.18% ) 19.3 kB
Grow ▲ +105 B (+0.46% ) 22.7 kB ▲ +35 B (+0.45% ) 7.76 kB
TableSortLabel ▲ +105 B (+0.14% ) 75.8 kB ▲ +35 B (+0.15% ) 24 kB
ToggleButton ▲ +105 B (+0.14% ) 74.6 kB ▲ +35 B (+0.15% ) 23.5 kB
Badge ▲ +105 B (+0.16% ) 63.9 kB ▲ +34 B (+0.17% ) 19.8 kB
Breadcrumbs ▲ +105 B (+0.16% ) 66.5 kB ▲ +34 B (+0.16% ) 20.9 kB
IconButton ▲ +105 B (+0.14% ) 74.6 kB ▲ +34 B (+0.15% ) 23.2 kB
ListSubheader ▲ +105 B (+0.17% ) 61.3 kB ▲ +34 B (+0.18% ) 19.2 kB
MobileStepper ▲ +105 B (+0.16% ) 66.3 kB ▲ +34 B (+0.16% ) 20.7 kB
NativeSelect ▲ +105 B (+0.14% ) 75.3 kB ▲ +34 B (+0.14% ) 23.7 kB
RadioGroup ▲ +105 B (+0.17% ) 61.8 kB ▲ +34 B (+0.18% ) 19.3 kB
Rating ▲ +105 B (+0.15% ) 68.5 kB ▲ +34 B (+0.16% ) 21.9 kB
SnackbarContent ▲ +105 B (+0.16% ) 64.2 kB ▲ +34 B (+0.17% ) 20.2 kB
TableCell ▲ +105 B (+0.17% ) 62.6 kB ▲ +34 B (+0.17% ) 19.6 kB
@material-ui/core[umd] ▲ +105 B (+0.03% ) 310 kB ▲ +33 B (+0.04% ) 89.2 kB
Avatar ▲ +105 B (+0.17% ) 61.3 kB ▲ +33 B (+0.17% ) 19.3 kB
Button ▲ +105 B (+0.13% ) 77.9 kB ▲ +33 B (+0.14% ) 23.8 kB
Chip ▲ +105 B (+0.13% ) 81 kB ▲ +33 B (+0.13% ) 24.7 kB
docs.main ▲ +105 B (+0.02% ) 606 kB ▲ +33 B (+0.02% ) 193 kB
ExpansionPanel ▲ +105 B (+0.15% ) 69.7 kB ▲ +33 B (+0.15% ) 21.7 kB
Fab ▲ +105 B (+0.14% ) 75.3 kB ▲ +33 B (+0.14% ) 23.4 kB
StepConnector ▲ +105 B (+0.17% ) 61.3 kB ▲ +33 B (+0.17% ) 19.2 kB
StepIcon ▲ +105 B (+0.17% ) 63.2 kB ▲ +33 B (+0.17% ) 19.6 kB
SvgIcon ▲ +105 B (+0.17% ) 61.6 kB ▲ +33 B (+0.17% ) 19.2 kB
Typography ▲ +105 B (+0.17% ) 62.2 kB ▲ +33 B (+0.17% ) 19.4 kB
@material-ui/core ▲ +105 B (+0.03% ) 351 kB ▲ +32 B (+0.03% ) 95.9 kB
@material-ui/lab ▲ +105 B (+0.06% ) 171 kB ▲ +32 B (+0.06% ) 51.6 kB
ButtonBase ▲ +105 B (+0.15% ) 72.5 kB ▲ +32 B (+0.14% ) 22.7 kB
Collapse ▲ +105 B (+0.16% ) 66.4 kB ▲ +32 B (+0.16% ) 20.5 kB
FormControl ▲ +105 B (+0.17% ) 62.9 kB ▲ +32 B (+0.16% ) 19.5 kB
FormLabel ▲ +105 B (+0.17% ) 62 kB ▲ +32 B (+0.17% ) 19.2 kB
InputLabel ▲ +105 B (+0.16% ) 63.9 kB ▲ +32 B (+0.16% ) 19.9 kB
StepContent ▲ +105 B (+0.16% ) 67.5 kB ▲ +32 B (+0.15% ) 21 kB
StepLabel ▲ +105 B (+0.16% ) 67.1 kB ▲ +32 B (+0.15% ) 21 kB
TablePagination ▲ +105 B (+0.08% ) 139 kB ▲ +32 B (+0.08% ) 40.6 kB
List ▲ +105 B (+0.17% ) 60.9 kB ▲ +31 B (+0.16% ) 18.9 kB
MenuItem ▲ +105 B (+0.14% ) 76.6 kB ▲ +31 B (+0.13% ) 23.9 kB
Popover ▲ +105 B (+0.13% ) 81.1 kB ▲ +31 B (+0.12% ) 25 kB
ListItem ▲ +105 B (+0.14% ) 75.6 kB ▲ +30 B (+0.13% ) 23.6 kB
Paper ▲ +105 B (+0.17% ) 60.8 kB ▲ +30 B (+0.16% ) 18.9 kB
Tooltip ▲ +105 B (+0.11% ) 99 kB ▲ +30 B (+0.10% ) 31.3 kB
Backdrop ▲ +105 B (+0.16% ) 66.3 kB ▲ +29 B (+0.14% ) 20.4 kB
MenuList ▲ +105 B (+0.16% ) 64.5 kB ▲ +29 B (+0.14% ) 20.1 kB
OutlinedInput ▲ +105 B (+0.14% ) 72.6 kB ▲ +15 B (+0.07% ) 22.5 kB
FilledInput ▲ +105 B (+0.15% ) 72.1 kB ▲ +13 B (+0.06% ) 22.3 kB
Input ▲ +105 B (+0.15% ) 71 kB ▲ +13 B (+0.06% ) 22.1 kB
InputBase ▲ +105 B (+0.15% ) 69.1 kB ▲ +13 B (+0.06% ) 21.6 kB
@material-ui/styles -- 50.8 kB -- 15.4 kB
@material-ui/system -- 14.8 kB -- 4.06 kB
ClickAwayListener -- 3.87 kB -- 1.56 kB
colorManipulator -- 3.83 kB -- 1.52 kB
docs.landing -- 55.8 kB -- 14.3 kB
Modal -- 14.2 kB -- 4.96 kB
NoSsr -- 2.19 kB -- 1.04 kB
Popper -- 28.5 kB -- 10.2 kB
Portal -- 2.87 kB -- 1.3 kB
RootRef -- 4.43 kB -- 1.67 kB
TextareaAutosize -- 5.06 kB -- 2.11 kB
useAutocomplete -- 12.1 kB -- 4.47 kB
useMediaQuery -- 2.49 kB -- 1.05 kB

Generated by 🚫 dangerJS against 636b203

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eps1lon
Copy link
Member Author

eps1lon commented Nov 15, 2019

I wasn't able in the past to communicate why throwing is better than logging. I hope it is clearer now when and why this is better.

@oliviertassinari
Copy link
Member

oliviertassinari commented Nov 15, 2019

@eps1lon I wouldn't mind if we wrap it with a if (process.env.NODE_ENV !== 'production') { logic. It would change the control flow, but with scrutiny, it could be OK. Anyway, error minification, like React does, could make sense for us in a distant future (1 year?).

@eps1lon
Copy link
Member Author

eps1lon commented Nov 15, 2019

Anyway, error minification, like React does, could make sense for us in a distant future (1 year?).

Definitely. I did some experiments a few months ago but the savings were very small compared to the build complexity. I was kind of hoping someone would build a babel plugin for it 😄

@eps1lon eps1lon changed the title [getContrastText] Throw descriptive exception when passing falsy argu… [getContrastText] Throw descriptive exception when passing falsy argument Nov 15, 2019
@eps1lon eps1lon merged commit 4ce0f41 into mui:master Nov 15, 2019
@eps1lon eps1lon deleted the feat/createMuiTheme/squash-messages branch November 15, 2019 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants