diff --git a/dim b/dim
index 35dba406e9991fed69525d89e335b096fe2cc807..9fc2e407be95643486ae05465de21b69829143d5 100755
--- a/dim
+++ b/dim
@@ -2296,6 +2296,14 @@ if ! declare -n subcmd=dim_alias_${subcommand//-/_} &> /dev/null || \
 	subcmd="$subcommand"
 fi
 
+# look up the function by the subcommand name
+subcmd_func=dim_${subcmd//-/_}
+if ! declare -f $subcmd_func >/dev/null; then
+	echoerr "'$subcommand' is not a dim command."
+	dim_usage
+	exit 1
+fi
+
 #
 # Sanity checks.
 #
@@ -2307,14 +2315,6 @@ if [[ -n "${__dim_running:-}" ]]; then
 fi
 export __dim_running=1
 
-# look up the function by the subcommand name
-subcmd_func=dim_${subcmd//-/_}
-if ! declare -f $subcmd_func >/dev/null; then
-	echoerr "'$subcommand' is not a dim command."
-	dim_usage
-	exit 1
-fi
-
 # Commands useful for developers don't need a full dim setup
 if list_developer_commands | grep -qx $subcmd; then
 	if [ -r $DIM_PREFIX/drm-rerere/$integration_config ]; then